Click here to Skip to main content
15,888,610 members
Articles / Desktop Programming / MFC
Article

Pie Chart Control

Rate me:
Please Sign up or sign in to vote.
4.25/5 (11 votes)
18 Aug 2001 116.9K   5.7K   57   5
This control creates a simple Pie Chart in a dialog

Sample Image - pie_chart_ctrl.gif

Introduction

This control class CPieChartCtrl is derived from CWnd. The purpose is to create a simple 2D pie chart in a dialog. The code is created and compiled with Visual C++ 5.0 SP3 under Windows 98.

How to use

  1. Use the MS Visual C++ dialog editor to place a custom control on the dialog, and enter "PIE_CHART_CTRL" as the Class name.

  2. Add a CPieChartCtrl class member in the header file
    #include "PieChartCtrl.h"
    ...
    CPieChartCtrl m_wndChart;
  3. Subclass the class member with the control in InitDialog()
    m_wndChart.SubclassDlgItem(IDC_PIECHART1, this); //IDC_PIECHART1 is the control ID
  4. Use these functions to edit to chart
    // SetTitle(CString) - Set the chart title text
    m_wndChart.SetTitle("Chart Title");
    
    // Reset() - Reset the chart and delete all pieces
    m_wndChart.Reset();
    
    // AddPiece(COLORREF colorBack, COLORREF colorText, 
    //            int nAngle, int strInfo = "");
    // Add one piece into the chart
    m_wndChart.AddPiece(colorBack, colorText, nAngle, strInfo);

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
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralUse the PieChartCtrl.cpp for Commercial Application Pin
mayocheng6-Jan-10 16:47
mayocheng6-Jan-10 16:47 
GeneralUse for commercial app Pin
minimal_objects25-Aug-08 5:07
minimal_objects25-Aug-08 5:07 
Questionadding this to an already existing MFC project? Pin
Member 35202051-Feb-07 11:10
Member 35202051-Feb-07 11:10 
GeneralFix to draw complete circle Pin
bkowald27-Oct-04 5:30
bkowald27-Oct-04 5:30 
Sometimes I have things that are 100 percent. (100 percent project completed, 100 percent customer satifaction etc) and the pie graph wouldn't draw an angle of 360 to fill in the circle.

So I commented out the line
//if (pt2!=pt1)
memDC.Pie(m_rectChart, pt2, pt1);

in the OnPaint() handler.

Now it fills in the correct color for 100 percent. If I draw something that is 100 percent (angle of 360) then I don't attempt to draw anything else that has 0, as that will write over it.

Brian

Generallets add more to it Pin
Ashok Jaiswal9-Apr-02 8:20
Ashok Jaiswal9-Apr-02 8:20 

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.