CGraph - Graph Class for Plotting Groups of Data

Have you ever tried to find a usable graph and chart class for plotting groups of data? I have. And when trying to find some cheap or free classes for plotting graph data, I found very few.

Tired of this predicament, I finally took the plunge and decided it was time to design them myself. It's a lot like trying to re-invent the wheel... because when the wheel costs $800 on the average, maybe it is time for re-inventing :)

So, here's my version of graph plotting : CGraph

Here's what it looks like during implementation :

I created a test application (testdraw) and used a menu option to show the many types of graphs created by my CGraph class and its helper classes (CGraphLegend, CGraphSeries).

A bar chart (I used bowling-type scores for the values) :

Sample Image

A line graph :

Sample Image

A pie graph, allowing multiple pies for simultaneous comparisons :

Sample Image

Since some people like to put graphs in a dialog, I did that too:

Sample Image

New in version 2 is the ability to print. Here's a print preview :

Sample Image

It also allows printing for line and pie graphs as well.

Version 3 additions :

Scatter Graphs :

Sample Image

Box-Whisker Graphs :

Sample Image

Stacked Bar Graphs :

Sample Image

XY Line Graphs :

Sample Image

3D Bar Graphs :

Sample Image

3D Stacked Bar Graphs :

Sample Image

3D Line Graphs (tape graph) :

Sample Image

3D Pie Graphs :

Sample Image

Version 3.0 also introduces multi-quadrant graphs. However, I have only implemented this for bar graphs (for now). Graphs can be displayed in 1 quadrant (as seen above), in 2 quadrants (either with the Y-axis splitting the middle of the X-axis, or the X-Axis splitting the middle of the Y-axis), or in 4 quadrants.

The quadrant display is still in development, so the printing of it has not yet been completed....I'll update my website with updates for it as I complete them (I didn't want to delay the other graphs too long). Some of the pages for individual graph types are also incomplete until I have time to complete the quadrant displays for those graphs.

I'm still unhappy with how the 3D Pies draw and print, so I may be updating these as time permits.

Patches :
     3.0.1 - July 26, 2001
          - fixed problem with non-0 based tick limits.
          - fixed problem with RemoveAllData() function causing GPF.

Downloads

Download sample program - 694 Kb
Download CGraph class files - 535 Kb (includes help file)
HTML Help - Required to use the help files (and IE 3.0 is also required)
      If using Visual Studio 6, you probably have this installed
      already, though you may want this newer version.

The help and test program are continuously being modified and improved. It is my hope to add a graph wizard to the test program so users can input their values and graph type, and the graph will be generated for them, as well as a sneak-peek at the code to generate the graph.

Usage

In the sample program, I have attempted to use every command in the CGraph and other classes. To use the classes, include them in your project and at the top of the file using them. To build a simple graph, follow these guidelines :

1.  Create a graph object.  You can pass a parameter for graph type if desired.
2.  Set your graph type, if not done in step 1.
         See help file for values to use for type.
3.  Create a legend object.  Use the SetLegend function in the CGraph to 
         add it to the graph.
4.  Create a set of series / data groups.  Use the AddSeries function in 
         the CGraph to add them to the graph.
5.  Perform an Invalidate ... this will force your OnDraw function to execute.
6.  In the OnDraw function, do a graph->DrawGraph(pDC); to draw the graph.

I have attempted to provide a fairly detailed help file for use with these classes. If not sufficient, mail me and let me know what I can do to improve it.

Environment: VC6, NT4 SP5, WIN 95, WIN 98



Comments

  • There are no comments yet. Be the first to comment!

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

Top White Papers and Webcasts

  • Lenovo recommends Windows 8 Pro. "I dropped my laptop getting out of the taxi." This probably sounds familiar to most IT professionals. If your employees are traveling, you know their devices are in for a rough go. Whether it's a trip to the conference room or a convention out of town, any time equipment leaves a user's desk it is at risk of being put into harm's way. Stay connected at all times, whether at the office or on the go, with agile, durable, and flexible devices like the Lenovo® …

  • Live Event Date: September 23, 2015 @ 1:00 p.m. ET / 10:00 a.m. PT The cloud is not just about a runtime platform for your projects – now, you can do your development in the cloud, too. Check out this upcoming eseminar to learn how the cloud improves your development experience and team collaboration. Join Dana Singleterry, Principal Product Manager for Oracle Dev Tools, as he discusses how to simplify every aspect of the development lifecycle, including requirements gathering, version management, code …

Most Popular Programming Stories

More for Developers

RSS Feeds

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