Pie Chart Control

 

Download Source Code

Download Example Project

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);

Last updated: 12 August 1998



Comments

  • Simple fix - to actually pass in percentages

    Posted by Legacy on 07/31/2002 12:00am

    Originally posted by: Frank

    BOOL CPieChartCtrl::AddPiece(COLORREF colorBack, COLORREF colorText, int nAngle, const CString& str, bool bAngleIsPercent)
    
    {
    // turn nAngle into what we like - a degree
    if (bAngleIsPercent) // - ex 17%
    nAngle = (360 * nAngle/100);

    ...
    }

    it could also be more ellaborate - taking floats instead of ints and so on...

    Reply
  • Program is good but.........

    Posted by Legacy on 01/22/2002 12:00am

    Originally posted by: Rajesh

    The program is good but instead of taking an angle, there should be some other way of passing data. Because, the program does not deal with angles(degrees) but only with percentages.

    Reply
  • Works fine but ................

    Posted by Legacy on 06/07/2001 12:00am

    Originally posted by: Chokri Oueslati

    It's a good job. Unfortunatly the developer should have spent a little more time and implemented functionality to take both Base and values, the way it is right now is on a degree base.

    Reply
  • 11

    Posted by Legacy on 01/19/2000 12:00am

    Originally posted by: fool kim

    열라깨군...
    

    Reply
  • the app crashed after press return

    Posted by Legacy on 04/04/1999 12:00am

    Originally posted by: Amanda

    in the edit box, press return, then the app disappear.

    Reply
  • It works

    Posted by Legacy on 03/03/1999 12:00am

    Originally posted by: Sharon Fridman

    But There are some problems, especially with color scheme.
    Also for values not converted to degrees (i.e. some non-normalized values - specially double ones) there is sometimes a 1% origional (blue) leftover.
    Thanks for the writetr anyhow.
    To fix, one need to normalize himself to degrees summing to 360.

    Reply
  • It's good; Problem when one item is inserted

    Posted by Legacy on 09/28/1998 12:00am

    Originally posted by: Nikos Papakostas

    It's simple and good. However, when only one item is inserted and angle 
    
    is equal to 360, the background colour is set to the original settings
    (blue) and not to the colour declared in the CPieChartCtrl::AddPiece()
    function.
    From a first look, it seems that if the 2 following lines are inserted
    under the line 135 of the file "PieChartCtrl.cpp", the problem is fixed:

    else if (nCount == 1)
    memDC.Ellipse(m_rectChart);

    The control was tested on a NT 4.0 SP3 machine with VC++ 5.0.


    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: May 6, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT While you likely have very good reasons for remaining on WinXP after end of support -- an estimated 20-30% of worldwide devices still are -- the bottom line is your security risk is now significant. In the absence of security patches, attackers will certainly turn their attention to this new opportunity. Join Lumension Vice President Paul Zimski in this one-hour webcast to discuss risk and, more importantly, 5 pragmatic risk mitigation techniques …

  • Instead of only managing projects organizations do need to manage value! "Doing the right things" and "doing things right" are the essential ingredients for successful software and systems delivery. Unfortunately, with distributed delivery spanning multiple disciplines, geographies and time zones, many organizations struggle with teams working in silos, broken lines of communication, lack of collaboration, inadequate traceability, and poor project visibility. This often results in organizations "doing the …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds