ChartDirector Ver 3.0 (C++ Edition)

Symbol Line Chart




This example demonstrates using symbols to represent data points, and putting data labels on top of the symbols.

Note that this example uses a 1 x 2 pixel pattern as the title background.

Source Code Listing

[The following project is available in "cppdemo/symbolline".]
#include "chartdir.h" int main(int argc, char *argv[]) { //The data for the line chart double data0[] = {60.2, 51.7, 81.3, 48.6, 56.2, 68.9, 52.8}; double data1[] = {30.0, 32.7, 33.9, 29.5, 32.2, 28.4, 29.8}; const char *labels[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; //Create a XYChart object of size 300 x 180 pixels, with a pale yellow //(0xffffc0) background, a black border, and 1 pixel 3D border effect. XYChart *c = new XYChart(300, 180, 0xffffc0, 0x0, 1); //Set the plotarea at (45, 35) and of size 240 x 120 pixels, with white //background. Turn on both horizontal and vertical grid lines with light //grey color (0xc0c0c0) c->setPlotArea(45, 35, 240, 120, 0xffffff, -1, -1, 0xc0c0c0, -1); //Add a legend box at (45, 12) (top of the chart) using horizontal layout //and 8 pts Arial font Set the background and border color to Transparent. c->addLegend(45, 12, false, "", 8)->setBackground(Transparent); //Add a title to the chart using 9 pts Arial Bold/white font. Use a 1 x 2 //bitmap pattern as the background. int pattern[] = {0x4000, 0x8000}; c->addTitle("Server Load (Jun 01 - Jun 07)", "arialbd.ttf", 9, 0xffffff )->setBackground(c->patternColor(IntArray(pattern, sizeof(pattern)/sizeof(*pattern)), 2)); //Set the y axis label format to nn% c->yAxis()->setLabelFormat("{value}%"); //Set the labels on the x axis c->xAxis()->setLabels(StringArray(labels, sizeof(labels)/sizeof(*labels))); //Add a line layer to the chart Layer *layer = c->addLineLayer(); //Add the first line. Plot the points with a 7 pixel square symbol layer->addDataSet(DoubleArray(data0, sizeof(data0)/sizeof(*data0)), 0xcf4040, "Peak")->setDataSymbol(SquareSymbol, 7); //Add the second line. Plot the points with a 9 pixel dismond symbol layer->addDataSet(DoubleArray(data1, sizeof(data1)/sizeof(*data1)), 0x40cf40, "Average")->setDataSymbol(DiamondSymbol, 9); //Enable data label on the data points. Set the label format to nn%. layer->setDataLabelFormat("{value|0}%"); //output the chart c->makeChart("symbolline.png"); //free up resources delete c; return 0; }