Click here to Skip to main content
15,895,084 members
Articles / Desktop Programming / MFC
Article

Series Values inside Pie Chart.

Rate me:
Please Sign up or sign in to vote.
3.50/5 (2 votes)
5 Oct 2003 51.4K   12   1
Display values inside Pie Chart.

Sample Image - SeriesValueInsidePieChart.gif

Introduction

This article shows one way of displaying values inside Pie chart.

Using the code

The MSVC ide will include only mschart.h only in the PieChartView.h

//{{AFX_INCLUDES()
#include "mschart.h"
//}}AFX_INCLUDES
</CODE>

Now include all the below show header files in the PieChartView.h file...

//{{AFX_INCLUDES()
#include "mschart.h"
#include "vcplot.h"
#include "vcseriescollection.h"
#include "vcseries.h"
#include "vcdatapoint.h"
#include "vcdatapoints.h"
#include "vcdatapointlabel.h"
#include "font.h"
//}}AFX_INCLUDES
</CODE>

Next in the InitialUpdate() method of FrameView class add the following code.

void CPieChartView::OnInitialUpdate()
{
    CFormView::OnInitialUpdate();
    GetParentFrame()->RecalcLayout();
    ResizeParentToFit();
    
    int count = m_MSChart.GetPlot().GetSeriesCollection().Count();
    CY fontSize;
    fontSize.int64 = 8; 
    for(int i = 1; i< count; i++)
    {
        m_MSChart.GetPlot().GetSeriesCollection().GetItem(i).GetDataPoints().GetItem (-1).GetDataPointLabel().SetLocationType(3);    
        m_MSChart.GetPlot().GetSeriesCollection().GetItem(i).GetDataPoints().GetItem (-1).GetDataPointLabel().SetComponent(2) ;   
        m_MSChart.GetPlot().GetSeriesCollection().GetItem(i).GetDataPoints().GetItem (-1).GetDataPointLabel().SetPercentFormat("0%");   
    }
}
</CODE>

Points of Interest

The same operation in MS Visual Basic looks like this..

 For i = 1 To .Plot.SeriesCollection.Count
         With .Plot.SeriesCollection(i).DataPoints(-1).DataPointLabel
            .LocationType = VtChLabelLocationTypeOutside
            .Component = VtChLabelComponentPercent
            .PercentFormat = "0%"
            .VtFont.Size = 10
         End With
      Next i
</CODE>

Am not able to set the font size in the MSVC version... any one get to know please let me know.

History

None.

Thanks!!

Happying Pie Charting!!!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionSetting Custom Text Inside Chart?? Pin
Christopher Stratmann31-Mar-06 3:04
Christopher Stratmann31-Mar-06 3:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.