Environment: Windows 95/98, Visual C++ 5.0 SP3
These are two classes I'm using to draw easy (absolutely not complex) graphs. I wrote it because I need a light (and cheap) control that could solve some problems about data showing.
What This Control Can Do
- draw on the same chart few (up to 64, but you can change if you prefer) graphs with different styles
- each graph can has up to 32k data (I never try this !)
- draw NULL datas (undrawing them) so that you can show graphs with different X timebase
- copy to clipboard
- copy to file
What This Control Can Not Do
- show data in 3d styles
- print graph directly to printer
- do a lot of things that I don't remember at this time...
How to use it
- First you must include the two classes in you project: add the files HMXChart.* and HMXDataset.* in your project
- include the HMXChart.h header in the CFormView that will show chart; the form must contain a static text control (modify its ID, e.g. IDC_CHART)
- create an object (in your formview object) derived from CHMXChart
- in formview initialization routine subclass the static text control
- set data and make-up
To set the data must be used following function
m_chart.SetData ( n, xxx );where n represents the dataset, and xxx is the value (double). Every time this function is called a new value is added to the dataset. If you want modify a specific value, use this function:
m_chart.SetData ( n, idx, xxx );where n is the dataset, idx is the idx-th element (zero based index), and xxx is the new value.
To create a new dataset its enought that a single value is added.
Following questions convinced me to design a new feature for this chart: NULL data.
What about if I have an hole in my data?
This is an example:
I have 2 datasets (Y1 and Y2):
HMX_DATASET_VALUE_INVALID = 1.7976931348623158e+308What about if a value is 1.7976931348623158e+308?
You can set it to 1.7976931348623158e+308 - 1, having a little error :)
In the example you can set to HMX_DATASET_VALUE_INVALID all the values that have no digits.
Even if the HMX_DATASET_VALUE_INVALID is a right concept for all dataset styles, in vertical bar style the value HMX_DATASET_VALUE_INVALID looks like 0.0, because all bars (positive and negative) starts from the zero line, thus the value 0.0 is represented with a 0 height bar.
There are three data formats: line, vertical bar and area; and the function to use to set the right format is:
m_chart.SetDatasetStyle( n, xxx );where n is the dataset to modify and xxx can be:
HMX_DATASET_STYLE_LINE, HMX_DATASET_STYLE_VBAR, HMX_DATASET_STYLE_AREA;If the style is line, it is possible to define a marker with the function
m_chart.SetDatasetMarker( n, xxx );There are 4 different markers:
HMX_DATASET_MARKER_TRI, HMX_DATASET_MARKER_BOX, HMX_DATASET_MARKER_SPH, HMX_DATASET_MARKER_DIA,that correspond to a triangle (with vertex up), a square box, a shere and a diamond (45 degree rotated box). The marker size depends on the pen size. Please note that with small size box, sphere and diamond have the same look, reducing the readability.
To set the pen size use following function:
m_chart.SetDatasetPenSize( n, size );If you're showing a line style graph, the pen size corresponds to the number of pixel used to draw the line; if the style is vertical bar, then the pen size corresponds to the width of the bar; in this case that number must be between 1 and 10; 1 is the smallest bar, 10 is the larger (occupies all the bar space). See the example and try to modify this value (an example is better than 1k words).
It's possible (of course) to set the X and Y labels; Y labels depend on the datasets and on the Y Ticks, X labels are added manually. They're strings, so it's possible to show numbers, text, date and so on.
Another interesting function allows the chart to have a good readability: rounding. It's possible to round the upper and lower chart limits to the multiple of each number, usually 2, 5, 10, 20, 500, and so on. This is its use:
m_chart.SetRoundY( n );where n is the rounding value. Try to modify the example to see what it does mean.
There are al lot of self-explaining functions that improve chart readability.