int main(int argc, char *argv[]) { // The tasks for the gantt chart const char *labels[] = {"Market Research", "Define Specifications", "Overall Archiecture", "Project Planning", "Detail Design", "Software Development", "Test Plan", "Testing and QA", "User Documentation"}; // The task index, start date, end date and color for each bar double taskNo[] = {0, 0, 1, 2, 3, 4, 5, 6, 6, 7, 8, 8}; double startDate[] = {chartTime(2004, 8, 16), chartTime(2004, 10, 4), chartTime( 2004, 8, 30), chartTime(2004, 9, 13), chartTime(2004, 9, 20), chartTime(2004, 9, 27), chartTime(2004, 10, 4), chartTime(2004, 10, 4), chartTime(2004, 10, 25), chartTime(2004, 11, 1), chartTime(2004, 10, 18), chartTime(2004, 11, 8)} ; double endDate[] = {chartTime(2004, 8, 30), chartTime(2004, 10, 18), chartTime( 2004, 9, 13), chartTime(2004, 9, 27), chartTime(2004, 10, 4), chartTime(2004, 10, 11), chartTime(2004, 11, 8), chartTime(2004, 10, 18), chartTime(2004, 11, 8), chartTime(2004, 11, 22), chartTime(2004, 11, 1), chartTime(2004, 11, 22)} ; int colors[] = {0x00cc00, 0x00cc00, 0x00cc00, 0x0000cc, 0x0000cc, 0xcc0000, 0xcc0000, 0x0000cc, 0xcc0000, 0xcc0000, 0x00cc00, 0xcc0000}; // Create a XYChart object of size 620 x 325 pixels. Set background color to // light red (0xffcccc), with 1 pixel 3D border effect. XYChart *c = new XYChart(620, 325, 0xffcccc, 0x000000, 1); // Add a title to the chart using 15 points Times Bold Itatic font, with white // (ffffff) text on a dark red (800000) background c->addTitle("Mutli-Color Gantt Chart Demo", "timesbi.ttf", 15, 0xffffff )->setBackground(0x800000); // Set the plotarea at (140, 55) and of size 460 x 200 pixels. Use alternative // white/grey background. Enable both horizontal and vertical grids by setting // their colors to grey (c0c0c0). Set vertical major grid (represents month // boundaries) 2 pixels in width c->setPlotArea(140, 55, 460, 200, 0xffffff, 0xeeeeee, Chart::LineColor, 0xc0c0c0, 0xc0c0c0)->setGridWidth(2, 1, 1, 1); // swap the x and y axes to create a horziontal box-whisker chart c->swapXY(); // Set the y-axis scale to be date scale from Aug 16, 2004 to Nov 22, 2004, with // ticks every 7 days (1 week) c->yAxis()->setDateScale(chartTime(2004, 8, 16), chartTime(2004, 11, 22), 86400 * 7); // Set multi-style axis label formatting. Month labels are in Arial Bold font in // "mmm d" format. Weekly labels just show the day of month and use minor tick // (by using '-' as first character of format string). c->yAxis()->setMultiFormat(Chart::StartOfMonthFilter(), "<*font=arialbd.ttf*>{value|mmm d}", Chart::StartOfDayFilter(), "-{value|d}") ; // Set the y-axis to shown on the top (right + swapXY = top) c->setYAxisOnRight(); // Set the labels on the x axis c->xAxis()->setLabels(StringArray(labels, sizeof(labels)/sizeof(labels[0]))); // Reverse the x-axis scale so that it points downwards. c->xAxis()->setReverse(); // Set the horizontal ticks and grid lines to be between the bars c->xAxis()->setTickOffset(0.5); // Add some symbols to the chart to represent milestones. The symbols are added // using scatter layers. We need to specify the task index, date, name, symbol // shape, size and color. double coor1[] = {1}; double date1[] = {chartTime(2004, 9, 13)}; c->addScatterLayer(DoubleArray(coor1, sizeof(coor1)/sizeof(coor1[0])), DoubleArray(date1, sizeof(date1)/sizeof(date1[0])), "Milestone 1", Chart::Cross2Shape(), 13, 0xffff00); double coor2[] = {3}; double date2[] = {chartTime(2004, 10, 4)}; c->addScatterLayer(DoubleArray(coor2, sizeof(coor2)/sizeof(coor2[0])), DoubleArray(date2, sizeof(date2)/sizeof(date2[0])), "Milestone 2", Chart::StarShape(5), 15, 0xff00ff); double coor3[] = {5}; double date3[] = {chartTime(2004, 11, 8)}; c->addScatterLayer(DoubleArray(coor3, sizeof(coor3)/sizeof(coor3[0])), DoubleArray(date3, sizeof(date3)/sizeof(date3[0])), "Milestone 3", Chart::TriangleSymbol, 13, 0xff9933); // Add a multi-color box-whisker layer to represent the gantt bars BoxWhiskerLayer *layer = c->addBoxWhiskerLayer2(DoubleArray(startDate, sizeof(startDate)/sizeof(startDate[0])), DoubleArray(endDate, sizeof(endDate)/sizeof(endDate[0])), DoubleArray(), DoubleArray(), DoubleArray(), IntArray(colors, sizeof(colors)/sizeof(colors[0]))); layer->setXData(DoubleArray(taskNo, sizeof(taskNo)/sizeof(taskNo[0]))); layer->setBorderColor(Chart::SameAsMainColor); // Divide the plot area height ( = 200 in this chart) by the number of tasks to // get the height of each slot. Use 80% of that as the bar height. layer->setDataWidth(200 * 4 / 5 / (sizeof(labels) / sizeof(labels[0]))); // Add a legend box at (140, 265) - bottom of the plot area. Use 8 pts Arial Bold // as the font with auto-grid layout. Set the width to the same width as the plot // area. Set the backgorund to grey (dddddd). LegendBox *legendBox = c->addLegend2(140, 265, Chart::AutoGrid, "arialbd.ttf", 8) ; legendBox->setWidth(461); legendBox->setBackground(0xdddddd); // The keys for the scatter layers (milestone symbols) will automatically be // added to the legend box. We just need to add keys to show the meanings of the // bar colors. legendBox->addKey("Market Team", 0x00cc00); legendBox->addKey("Planning Team", 0x0000cc); legendBox->addKey("Development Team", 0xcc0000); // Output the chart c->makeChart("colorgantt.png"); //free up resources delete c; return 0; }
int main(int argc, char *argv[]) { // The data for the chart double data[] = {30, 28, 40, 55, 75, 68, 54, 60, 50, 62, 75, 65, 75, 89, 60, 55, 53, 35, 50, 66, 56, 48, 52, 65, 62}; // The labels for the chart const char *labels[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24"}; // Create a XYChart object of size 500 x 300 pixels, with a pale yellow // (0xffffc0) background, a black border, and 1 pixel 3D border effect XYChart *c = new XYChart(500, 300, 0xffffc0, 0x000000, 1); // Set the plotarea at (55, 50) and of size 420 x 205 pixels, with white // background. Turn on both horizontal and vertical grid lines with light grey // color (0xc0c0c0) c->setPlotArea(55, 50, 420, 205, 0xffffff)->setGridColor(0xc0c0c0, 0xc0c0c0); // Add a legend box at (55, 25) (top of the chart) with horizontal layout. Use 8 // pts Arial font. Set the background and border color to Transparent. LegendBox *legendBox = c->addLegend(55, 25, false, "", 8); legendBox->setBackground(Chart::Transparent); // Add keys to the legend box to explain the color zones legendBox->addKey("Normal Zone", 0x8033ff33); legendBox->addKey("Alert Zone", 0x80ff3333); // Add a title box to the chart using 13 pts Arial Bold Italic font. The title is // in CDML and includes embedded images for highlight. The text is white // (0xffffff) on a black background, with a 1 pixel 3D border. c->addTitle( "<*block,valign=absmiddle*><*img=star.png*><*img=star.png*> Y Zone Color " "Demo <*img=star.png*><*img=star.png*><*/*>", "arialbi.ttf", 13, 0xffffff )->setBackground(0x000000, -1, 1); // Add a title to the y axis c->yAxis()->setTitle("Energy Concentration (KJ per liter)"); // Set the labels on the x axis. c->xAxis()->setLabels(StringArray(labels, sizeof(labels)/sizeof(labels[0]))); // Display 1 out of 3 labels on the x-axis. c->xAxis()->setLabelStep(3); // Add a title to the x axis using CDML c->xAxis()->setTitle( "<*block,valign=absmiddle*><*img=clock.png*> Elapsed Time (hour)<*/*>"); // Set the axes width to 2 pixels c->xAxis()->setWidth(2); c->yAxis()->setWidth(2); // Add an area layer to the chart. The area is using a y zone color, where the // color is semi-transparent green below 60, and semi-transparent red above 60. c->addAreaLayer(DoubleArray(data, sizeof(data)/sizeof(data[0])), c->yZoneColor( 60, 0x8033ff33, 0x80ff3333)); // Add a custom CDML text at the bottom right of the plot area as the logo c->addText(475, 255, "<*block,valign=absmiddle*><*img=small_molecule.png*> <*block*>" "<*font=timesbi.ttf,size=10,color=804040*>Molecular\nEngineering<*/*>" )->setAlignment(Chart::BottomRight); // Output the chart c->makeChart("yzonecolor.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; }
int main(int argc, char *argv[]) { char buffer[256]; // The XY data of the first data series double dataX[] = {50, 55, 37, 24, 42, 49, 63, 72, 83, 59}; double dataY[] = {3.6, 2.8, 2.5, 2.3, 3.8, 3.0, 3.8, 5.0, 6.0, 3.3}; // Create a XYChart object of size 450 x 420 pixels XYChart *c = new XYChart(450, 420); // Set the plotarea at (55, 65) and of size 350 x 300 pixels, with white // background and a light grey border (0xc0c0c0). Turn on both horizontal and // vertical grid lines with light grey color (0xc0c0c0) c->setPlotArea(55, 65, 350, 300, 0xffffff, -1, 0xc0c0c0, 0xc0c0c0, -1); // Add a title to the chart using 18 point Times Bold Itatic font. c->addTitle("Server Performance", "timesbi.ttf", 18); // Add titles to the axes using 12 pts Arial Bold Italic font c->yAxis()->setTitle("Response Time (sec)", "arialbi.ttf", 12); c->xAxis()->setTitle("Server Load (TPS)", "arialbi.ttf", 12); // Set the axes line width to 3 pixels c->yAxis()->setWidth(3); c->xAxis()->setWidth(3); // Add a scatter layer using (dataX, dataY) c->addScatterLayer(DoubleArray(dataX, sizeof(dataX)/sizeof(dataX[0])), DoubleArray(dataY, sizeof(dataY)/sizeof(dataY[0])), "", Chart::DiamondSymbol, 11, 0x008000); // Add a trend line layer for (dataX, dataY) TrendLayer *trendLayer = c->addTrendLayer(DoubleArray(dataX, sizeof(dataX)/sizeof(dataX[0])), DoubleArray(dataY, sizeof(dataY)/sizeof(dataY[0])), 0x008000); // Set the line width to 3 pixels trendLayer->setLineWidth(3); // Add a 95% confidence band for the line trendLayer->addConfidenceBand(0.95, 0x806666ff); // Add a 95% confidence band (prediction band) for the points trendLayer->addPredictionBand(0.95, 0x8066ff66); // Add a legend box at (50, 30) (top of the chart) with horizontal layout. Use 10 // pts Arial Bold Italic font. Set the background and border color to // Transparent. LegendBox *legendBox = c->addLegend(50, 30, false, "arialbi.ttf", 10); legendBox->setBackground(Chart::Transparent); // Add entries to the legend box legendBox->addKey("95% Line Confidence", 0x806666ff); legendBox->addKey("95% Point Confidence", 0x8066ff66); // Display the trend line parameters as a text table formatted using CDML sprintf(buffer, "<*block*>Slope\nIntercept\nCorrelation\nStd Error<*/*> <*block*>%.4f " "sec/tps\n%.4f sec\n%.4f\n%.4f sec<*/*>", trendLayer->getSlope(), trendLayer->getIntercept(), trendLayer->getCorrelation(), trendLayer->getStdError()); TextBox *textbox = c->addText(56, 65, buffer, "arialbd.ttf", 8); // Set the background of the text box to light grey, with a black border, and 1 // pixel 3D border textbox->setBackground(0xc0c0c0, 0, 1); // Output the chart c->makeChart("confidenceband.png"); //free up resources delete c; return 0; }