int main(int argc, char *argv[]) { // The data for the area chart double data0[] = {42, 49, 33, 38, 51, 46, 29, 41, 44, 57, 59, 52, 37, 34, 51, 56, 56, 60, 70, 76, 63, 67, 75, 64, 51}; double data1[] = {50, 55, 47, 34, 42, 49, 63, 62, 73, 59, 56, 50, 64, 60, 67, 67, 58, 59, 73, 77, 84, 82, 80, 84, 98}; double data2[] = {87, 89, 85, 66, 53, 39, 24, 21, 37, 56, 37, 23, 21, 33, 13, 17, 14, 23, 16, 25, 29, 30, 45, 47, 46}; // The timestamps on the x-axis double labels[] = {chartTime(1996, 1, 1), chartTime(1996, 4, 1), chartTime(1996, 7, 1), chartTime(1996, 10, 1), chartTime(1997, 1, 1), chartTime(1997, 4, 1), chartTime(1997, 7, 1), chartTime(1997, 10, 1), chartTime(1998, 1, 1), chartTime(1998, 4, 1), chartTime(1998, 7, 1), chartTime(1998, 10, 1), chartTime(1999, 1, 1), chartTime(1999, 4, 1), chartTime(1999, 7, 1), chartTime(1999, 10, 1), chartTime(2000, 1, 1), chartTime(2000, 4, 1), chartTime(2000, 7, 1), chartTime(2000, 10, 1), chartTime(2001, 1, 1), chartTime(2001, 4, 1), chartTime(2001, 7, 1), chartTime(2001, 10, 1), chartTime(2002, 1, 1)}; // Create a XYChart object of size 500 x 280 pixels, using 0xffffcc as background // color, with a black border, and 1 pixel 3D border effect XYChart *c = new XYChart(500, 280, 0xffffcc, 0, 1); // Set the plotarea at (50, 45) and of size 320 x 200 pixels with white // background. Enable horizontal and vertical grid lines using the grey // (0xc0c0c0) color. c->setPlotArea(50, 45, 320, 200, 0xffffff)->setGridColor(0xc0c0c0, 0xc0c0c0); // Add a legend box at (370, 45) using vertical layout and 8 points Arial Bold // font. LegendBox *legendBox = c->addLegend(370, 45, true, "arialbd.ttf", 8); // Set the legend box background and border to transparent legendBox->setBackground(Chart::Transparent, Chart::Transparent); // Set the legend box icon size to 16 x 32 pixels to match with custom icon size legendBox->setKeySize(16, 32); // Add a title to the chart using 14 points Times Bold Itatic font and white font // color, and 0x804020 as the background color c->addTitle("Quarterly Product Sales", "timesbi.ttf", 14, 0xffffff )->setBackground(0x804020); // Set the labels on the x axis. c->xAxis()->setLabels(DoubleArray(labels, sizeof(labels)/sizeof(labels[0]))); // Set multi-style axis label formatting. Start of year labels are displayed as // yyyy. For other labels, just show minor tick. c->xAxis()->setMultiFormat(Chart::StartOfYearFilter(), "{value|yyyy}", Chart::AllPassFilter(), "-"); // Add a percentage area layer to the chart AreaLayer *layer = c->addAreaLayer(Chart::Percentage); // Add the three data sets to the area layer, using icons images with labels as // data set names layer->addDataSet(DoubleArray(data0, sizeof(data0)/sizeof(data0[0])), 0x40ddaa77, "<*block,valign=absmiddle*><*img=service.png*> Service<*/*>"); layer->addDataSet(DoubleArray(data1, sizeof(data1)/sizeof(data1[0])), 0x40aadd77, "<*block,valign=absmiddle*><*img=software.png*> Software<*/*>"); layer->addDataSet(DoubleArray(data2, sizeof(data2)/sizeof(data2[0])), 0x40aa77dd, "<*block,valign=absmiddle*><*img=computer.png*> Hardware<*/*>"); // For a vertical stacked chart with positive data only, the last data set is // always on top. However, in a vertical legend box, the last data set is at the // bottom. This can be reversed by using the setLegend method. layer->setLegend(Chart::ReverseLegend); // Output the chart c->makeChart("percentarea.png"); //free up resources delete c; return 0; }
int main(int argc, char *argv[]) { // The x and y coordinates of the grid double dataX[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; double dataY[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // Use random numbers for the z values on the XY grid RanSeries *r = new RanSeries(999); DoubleArray dataZ = r->get2DSeries((int)(sizeof(dataX) / sizeof(dataX[0])), (int)(sizeof(dataY) / sizeof(dataY[0])), -0.9, 1.15); // Create a XYChart object of size 640 x 460 pixels XYChart *c = new XYChart(640, 460); // Set the plotarea at (30, 25) and of size 400 x 400 pixels. Use semi-transparent grey // (0xdd000000) horizontal and vertical grid lines c->setPlotArea(50, 25, 400, 400, -1, -1, Chart::Transparent, 0xdd000000, -1); // Set the x and y axis stems to transparent and the label font to 12pt Arial c->xAxis()->setColors(Chart::Transparent); c->yAxis()->setColors(Chart::Transparent); c->xAxis()->setLabelStyle("arial.ttf", 12); c->yAxis()->setLabelStyle("arial.ttf", 12); // Set the x-axis and y-axis scale c->xAxis()->setLinearScale(0, 10, 1); c->yAxis()->setLinearScale(0, 10, 1); // Add a contour layer using the given data ContourLayer *layer = c->addContourLayer(DoubleArray(dataX, (int)(sizeof(dataX) / sizeof(dataX[0 ]))), DoubleArray(dataY, (int)(sizeof(dataY) / sizeof(dataY[0]))), dataZ); // Move the grid lines in front of the contour layer c->getPlotArea()->moveGridBefore(layer); // Define the color scale double colorScale[] = {-0.8, 0x0066ff, -0.5, 0x66ccff, -0.3, 0x66ffff, 0, 0x88ff88, 0.4, 0x00ff00, 0.7, 0xffff00, 0.9, 0xff6600, 1.0, 0xcc0000, 1.1}; // Apply the color scale, and specify the underflow and overflow colors for regions exceeding // the color scale layer->colorAxis()->setColorScale(DoubleArray(colorScale, (int)(sizeof(colorScale) / sizeof( colorScale[0]))), 0x0000cc, 0x000000); // // Instead of displaying the color axis, we use a legend box to display the colors. This is // useful for colors that are unevenly spaced on the color axis. // // Add a legend box at (460, 25) with vertical layout, with 12pt Arial font, transparent // background and border, icon size of 15 x 15 pixels, and line spacing of 8 pixels. LegendBox *b = c->addLegend(460, 25, true, "arial.ttf", 12); b->setBackground(Chart::Transparent, Chart::Transparent); b->setKeySize(15, 15); b->setKeySpacing(0, 8); // Add the legend box entries b->addKey("> 1.1 (Critical)", 0x000000); b->addKey("1.0 to 1.1 (Alert)", 0xcc0000); b->addKey("0.9 to 1.0", 0xff6600); b->addKey("0.7 to 0.9", 0xffff00); b->addKey("0.4 to 0.7", 0x00ff00); b->addKey("0.0 to 0.4", 0x88ff88); b->addKey("-0.3 to 0.0", 0x66ffff); b->addKey("-0.5 to -0.3", 0x66ccff); b->addKey("-0.8 to -0.5", 0x0066ff); b->addKey("< -0.8", 0x0000cc); // Output the chart c->makeChart("contourlegend.png"); //free up resources delete r; delete c; return 0; }