Click here to Skip to main content
Click here to Skip to main content

Series Values inside Pie Chart.

By , 5 Oct 2003
 

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

About the Author

ShabuKC
Web Developer
India India
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionSetting Custom Text Inside Chart??memberchris17531 Mar '06 - 3:04 
I have been working with the Active X MSCharting class for about a week or so and I have come up with the issue of putting custom labels within the chart. I am using Microsoft Visual Studio 6.0 on Windows 2000 SP4. So far this is what I have found....
 
CVcSeriesCollection sc = m_chart.GetPlot().GetSeriesCollection();
// 2 will select the second series.
CVcSeries s = sc.GetItem(2);
CVcDataPoints dps = s.GetDataPoints();
// -1 will select all the datapoints in the series
CVcDataPoint dp = dps.GetItem(-1);
// 1 = VtChLabelLocationTypeAbovePoint which places the values ontop the bars.
dp.GetDataPointLabel().SetLocationType(1);
This works perfectly for displaying the values of all the datapoints above the bars in a selected series.
 
Now the Problem
I would like to put a custom label on top a datapoint like "8 hours". I have tried the following but get an error when calling dps.GetItem(1);
 
CVcSeriesCollection sc = m_chart.GetPlot().GetSeriesCollection();
CVcSeries s = sc.GetItem(2);
CVcDataPoints dps = s.GetDataPoints();
long l_Item_Count = dps.GetCount();
CVcDataPoint dp = dps.GetItem(1);
dp.GetDataPointLabel().SetLocationType(1);
dp.GetDataPointLabel().SetText("8 Hours");
 
Other Information
- There is a dp.GetDataPointLabel().SetCustom(bool) function but I have no idea how to use it. I can set this function to true after calling dps.GetItem(-1) but it seems to do nothing.
- The error that I get says "Index given is out of bounds" but the value that gets stored into l_Item_count is 5.
- This is how I am adding data to the chart. m_chart.GetDataGrid().SetData(ROW_NUM,COL_NUM,d_va lue,0); which I am pretty sure is correct.
- This is what is in my Visual Studios Output box after the exception is thrown..."First-chance exception in Testd.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception. Warning: Uncaught exception in WindowProc (returning 1)."
- I am not adding or modifing the columns or rows in the bar chart at all. I am just using the 5 generic rows and 4 generic columns built by the chart class.
- I can change the labels with the following function: m_chart.GetDataGrid().SetRowLabel(ROW_NUM,1,"RowA" );. The 1 is an index which does something but I dont know what. I have tried to set this value to 2 and 3 but I get errors. This may play a part in this problem I dont really know.
 

 
Thanks for taking the time to read my problem. Please responed with any information.
Thanks again.

 
Chris

 
Chris

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 6 Oct 2003
Article Copyright 2003 by ShabuKC
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid