2D Chart and 3D Waterfall Chart Control


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

Environment: Visual C++ 6.0,Win 95/98,NT4.0.
The print routine has been tested with HP Laserjet 4ML and Lexmark 3200, with Acrobat Writer by setting the resolution at 600 dpi.


The CChart class is the class derived from CWnd class. The class provides the functionality of Windows plotting chart control . The chart plotted from this class will look like the output of an Oscilloscope . By the way, I found that there is an article like this already posted here . So CChart3d is the derived class from CChart that will be able to plot data in 3D style.The demo project will will plot data in 2D and 3D like a Waterfall plot found in an expensive Signal Analyser.


CChart and CChart3d to your project First add these four files to your project. Chart3d.cpp , Chart3d.h , Chart.cpp and Chart.h . Then you can add the object to like this :
CChart m_Chart2d ;
CChart3d m_Chart3d;
After that you can customize,create and then update new data to chart respectively. In the demo project you can find the implementation of CChart and CChart3d in the routine
CWFDemoView::InitialUpdate();   // for customizing and creating chart
CWFDemoView::OnTimer();         // for updating data to chart
CWFDemoView::OnPrint(CDC *pDC); // for printing chart.

Customize Control

Customize control of chart can be done before and after the chart is created. If you change setting after the chart was created then call function Invalidate() to redrawn the chart.
  1. Setting Chart Title can be done by calling the function
    SetChartTitle(Cstring str)
  2. Setting Range of each axis can be done by calling the following functions:
    CChart::SetRange(double Xmin, double Xmax,
                     double Ymin, doubleYmax)
    Default: SetRange(-10,10,-10,10)
    CChart3d::SetRange3d(double Xmin, double Xmax,
                         double Ymin, double Ymax, 
                         double Zmin , double Zmax)
    Default: SetRange3d(0,100,0,20,0,100)
  3. Setting the Axiss Label can be done by calling the functions:
    CChart::SetAxisLabel(Cstring strLabelX , Cstring strLabelY)
  4. Setting the number of grid scale for each axis and the labels to be plotted on screen can be done by calling the functions:
    CChart::SetGridNumber(int nGridX , int nGridY)
    CChart3d::SetGridNumber3D(int nGridX, int nGridY, int nGridZ)
    Note: Grid labels will be automatic drawn according to the number of grid setting.
  5. Setting the Axis style by calling the function:
    CChart::SetAxisStyle(int nStyle)
                         //0: Single Quadrant
                         //1: Double Quadrant
                         //2: 4 Quadrant *default
  6. Customize color on chart Background Color can be modified with variable: m_BGColor. Axis color can be modified with variable: m_AxisColor. Grid color can be modified with variable: m_GridColor. Series plot color can be modified with variable: CSerie::m_plotColor.


    mChart.m_BGColor = RGB(255,0,0,)               //Set background color to red
    mChart.m_AxisColor = RGB(0,0,0);               // Set background color to black
    mChart.m_GridColor = RGB(120,120,120);         // Set grid color to gray .<
    mChart.mpSerie[0].m_plotColor = RGB(0,255,0) ; //Set series 0 color to green
  7. Set the number of series on chart by modify variable

    Note: The maximum series on the code is 60 but you can assemble it and change to any number is your want.

  8. Allocate number of points for all series by calling function:
    CChart::AllocSerie(int nSerie)

    Caution : Setting the number of series has to be done before calling this function

  9. Working with the Chart
    • Creating Chart - After you finished customizing the chart then call the function:
      Create(DWORD dwStyle, CRect &rect, CWnd *pParent, UINT id)


    • Updating Chart - You can update data for each series by calling function :
      SetXYValue(double x , double y , int index , int nSerieIdx).

      If you want chart to be redrawn function Invalidate() should be called . The chart background will be drawn as it was when the chart was first created then it will save the background in the buffer. But if you changed background color or grid color then you need to call the Invalidate() function with argument FALSE to force the chart background to be redrawn .

    • Printing Chart - In the demo project you can preview and print the chart . I have test the program with several printers. The function CChart::PrintChart(CDC *pDC,int x ,int y) is used for printing the chart.

      In the demo project I added this function in OnPrint(CDC *pDC) in CFormView class as example :

      void CWFDemoView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)


Download demo project - 29 Kb
Download source - 10 Kb


  • silverlight chart control

    Posted by rickwebb on 05/13/2008 09:03pm

    try visifire, you can create animated silverlight chart using it. added advantage is that it is under open source

    • looking for chart

      Posted by laronze on 07/03/2009 11:58am


    • fgg

      Posted by baoyin on 06/21/2009 07:25am


  • Adding user-def colors to the labels and title

    Posted by Radu on 11/16/2006 01:43pm

    Hi, This is a method to change the color for the labels and title. There are already member functions for this but they are not used. These are: m_TextLabelColor m_TextTitleColor In Chart.cpp add the following: in Method DrawGridLabel: after line: pDC->SetBkMode(TRANSPARENT); add: pDC->SetTextColor(m_TextLabelColor); in method DrawChartTitle after line oldbkmode = pDC->SetBkMode(TRANSPARENT) ; add: pDC->SetTextColor(m_TextTitleColor); and in file Chart3d.cpp in method DrawGridLabel after line oldbkmode = pDC->SetBkMode(TRANSPARENT) ; add: pDC->SetTextColor(m_TextLabelColor);

  • Nice program! but here is a free 3D waterfall display activex control

    Posted by foxden on 07/12/2005 03:50pm

    I wanted to write my 3D waterfall charting program based on your codes until I found this free 3D waterfall display activex contro: http://www.ultimaserial.com/UltimaWaterfall.html

    • My 2 cents

      Posted by foxden on 09/07/2005 04:51pm

      After playing with the two waterfall utilities, I will say both are fun: Kris' is more fun to learn and more object-oriented, and ultimawaterfall is just so easy to use!

  • i am trying to put more lines to the plotscene

    Posted by alakese on 09/10/2004 10:49am

    , but not succeeded yet

    • i am trying to put more lines to the plotscene

      Posted by Kris Jearakul on 10/13/2004 03:48am

      If you need a example file for 2 plots,please email me at kj831ca@yahoo.com Kris Jearakul

    • i am trying to put more lines to the plotscene

      Posted by Kris Jearakul on 10/13/2004 03:45am

      Sorry if I do double posted here. It has been long time since I logged on here. Here is the step to add more lines or series to plotscene on 2D Chart. 1. On CWFDemoView::OnInitialUpdate add this line m_Chart2d.nSerieCount = 2 ; before CChart::AllocSerie(n) is being called. 2. Update data to the new serie in CWFDemoView:OnTimer add this line -> m_Chart2d.SetXYValue((double)i,fabs(value * 0.5),i,1); m_Chart3d.SetXYValue((double)i,fabs(value),i,0) Please note the new plot will be 0.5 amplitude of the first plot. Best Regards Kris.

  • About Graphical (3D) representation using C/C++

    Posted by Legacy on 11/18/2003 08:00am

    Originally posted by: Rahul P Mokhadkar

    Dear SIr,
    I would like to request you to recommend some books on Graphical (3 D) representation using C/ C++ programming.
    Please guide me.

  • How Could I plot two values in same graph

    Posted by Legacy on 09/25/2003 07:00am

    Originally posted by: Vishal Sharma

    U have Really developed a nice utility.

  • Severe bug

    Posted by Legacy on 09/12/2003 07:00am

    Originally posted by: Jimmy B

    There is a severe bug in this code which will eventually consume all GDI resources making any screen drawing impossible. If you want to fix this code you will need to clean up after your objects which use the CreateCompatibleDC and CreateCompatibleBitmap calls. It clearly states in the MFC documentation that you must perform a DeleteObject or DeleteDC after using CreateCompatible... calls. If you do not, you will not release the limited GDI resources. Once all resources are consumed, you cannot draw to the screen any longer. Very nasty and hard to debug too.

    Take care.

    • DeleteDC

      Posted by alakese on 09/10/2004 10:46am

      In general, do not call this function; the destructor will do it for you. - msdn

  • Great work

    Posted by Legacy on 07/13/2003 07:00am

    Originally posted by: Alex F

    It takes a short time to learn how to use it. I used this control in my CodeProject article:

  • multiply plot?

    Posted by Legacy on 06/26/2003 07:00am

    Originally posted by: LUka Frodnik

    I've tried to add new plot, I've found some places in a code there its done for 1st plot, but I still see nothing changed

  • When are Waterfall Charts not Waterfall Charts ?

    Posted by Legacy on 04/01/2003 08:00am

    Originally posted by: Lori Hughes

    I've been searching for an add-in or macro - or something - to assist in creating Waterfall Charts.
    I came here and noticed all the help on offer - and thought, way cool!
    But then I noticed the Waterfall chart graphic looks like an 'area' chart. The Waterfall charts we use here look more like 'steps' up and down based on the data - wish I could draw what I mean here.
    So I wonder - are Waterfall charts different around the world?
    It's just got me really confused!
    I would really appreciate any assistance you are able to offer.
    Thank you so much.
    Kind regards,

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

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

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date