Lately in the forum we have been getting a lot of requests for charting Libraries
for windows while there are a lot of options for commercial libraries.

Not so much in terms of free ones.

The best I have come across is Dislin by the Max Planck Institute
but the biggest problem is that it draws in its own window or you
can save the chart as a jpg and load it into your app.

It doesnt just draw on a device context and be done with it.

In windows device contexts are very important for displaying on
screen or on a printer and everything else for that matter.

Anyway it struck me that in these cases its time to build your own library
that does things the way you want it to.

After all it's just a little math how hard could it be ?

And that is how I came up with ChartKM.lib and libChartKM.a
which are of course the same Library but for different compilers.

as usual I will post the code for it all and discuss the finer points
in detail later on.

First of all I have made the entire library available but I am going to
split it into 3 parts.

The first Tutorial Part 1 will discuss the Pie Chart making capabilities.

The second Tutorial Part 2 will discuss the Bar Chart making capabilities.

The third Tutorial Part 3 will discuss the Line Graph making capabilities.

Each Tutorial will have an example program to illustrate how to use
the Library. I think this is necessary, while the Library is fairly intuitive
It will be better if there is at least some discussion on how to use it.

As it gets fairly complex pretty quickly.

I may do an extension to the Library to include 3d Pie , Bar and Line charts
If I do this it will be again in 3 parts with the new 3d class being derived from the original class chartObject.

However I will be going back to work soon and time will be again at a premium.

On with the show then....

the library relies on the gdi32 library.

If you are using MSVC and the cl compiler you dont need to do anything
as I have included pragma comments to load the Library.

If you are using MinGW derivatives such as Code::Blocks , Dev C or Eclipse
with the gcc compiler your going to have to link to libgdi32.a

If you are using MSVC select an empty project go to

Project Properties->Configuration Properties->General

In the configuration type select -> Static library(.lib)

Change the character set to -> Use Multi Byte Character Set

as this is not a unicode build however it is not that hard to make it
a unicode build. This has been done so the code will run on as many compiler
suites as possible.

If your using Code::Blocks

Select Empty Project go to
Project Properties -> Build Targets
In Type change it to -> Static library from the drop down list.

For Both add a new .cpp file and call it ChartKM.cpp

For Both add a new .h file and call it ChartKM.h

This is important as we need the names as it appears above so our example
Programs will work correctly.
ChartKM.h

We draw our first line as our starting point, set the background color for text.
We call our functions GetTotal and GetFrequency.

Time to Explain about Pie Charts

The earliest known pie chart is generally credited to William Playfair's Statistical Breviary of 1801.

The pie chart is perhaps the most widely used statistical chart in the business world and the mass media. However, it has been criticized, and some recommend avoiding it, pointing out in particular that it is difficult to compare different sections of a given pie chart, or to compare data across different pie charts. Pie charts can be an effective way of displaying information in some cases, in particular if the intent is to compare the size of a slice with the whole pie, rather than comparing the slices among them. Pie charts work particularly well when the slices represent 25 to 50% of the data, but in general, other charts such as the bar chart or the Line chart, or non-graphical methods such as tables, may be more adapted for representing certain information. (Cite: http://en.wikipedia....wiki/Pie_chart)

We get the xradius and yradius of the circle we then do a lot of math pertaining to angles to construct the segments according to data size.
We then have series of if statements to fill the Pie Chart with the FloodFill statement.