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 names of the tasks const char *labels[] = {"Market Research", "Define Specifications", "Overall Archiecture", "Project Planning", "Detail Design", "Software Development", "Test Plan", "Testing and QA", "User Documentation"}; // the planned start dates and end dates for the tasks double startDate[] = {chartTime(2004, 8, 16), chartTime(2004, 8, 30), chartTime( 2004, 9, 13), chartTime(2004, 9, 20), chartTime(2004, 9, 27), chartTime(2004, 10, 4), chartTime(2004, 10, 25), chartTime(2004, 11, 1), chartTime(2004, 11, 8)}; double endDate[] = {chartTime(2004, 8, 30), chartTime(2004, 9, 13), chartTime( 2004, 9, 27), chartTime(2004, 10, 4), chartTime(2004, 10, 11), chartTime( 2004, 11, 8), chartTime(2004, 11, 8), chartTime(2004, 11, 22), chartTime( 2004, 11, 22)}; // the actual start dates and end dates for the tasks up to now double actualStartDate[] = {chartTime(2004, 8, 16), chartTime(2004, 8, 27), chartTime(2004, 9, 9), chartTime(2004, 9, 18), chartTime(2004, 9, 22)}; double actualEndDate[] = {chartTime(2004, 8, 27), chartTime(2004, 9, 9), chartTime(2004, 9, 27), chartTime(2004, 10, 2), chartTime(2004, 10, 8)}; // Create a XYChart object of size 620 x 280 pixels. Set background color to // light green (ccffcc) with 1 pixel 3D border effect. XYChart *c = new XYChart(620, 280, 0xccffcc, 0x000000, 1); // Add a title to the chart using 15 points Times Bold Itatic font, with white // (ffffff) text on a dark green (0x6000) background c->addTitle("Mutli-Layer Gantt Chart Demo", "timesbi.ttf", 15, 0xffffff )->setBackground(0x006000); // 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); // Add a red (ff0000) dash line to represent the current day c->yAxis()->addMark(chartTime(2004, 10, 8), c->dashLineColor(0xff0000, Chart::DashLine)); // 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); // Use blue (0000aa) as the color for the planned schedule int plannedColor = 0x0000aa; // Use a red hash pattern as the color for the actual dates. The pattern is // created as a 4 x 4 bitmap defined in memory as an array of colors. int pattern1[] = {0xffffff, 0xffffff, 0xffffff, 0xff0000, 0xffffff, 0xffffff, 0xff0000, 0xffffff, 0xffffff, 0xff0000, 0xffffff, 0xffffff, 0xff0000, 0xffffff, 0xffffff, 0xffffff}; int actualColor = c->patternColor(IntArray(pattern1, sizeof(pattern1)/sizeof(pattern1[0])), 4); // Add a box whisker layer to represent the actual dates. We add the actual dates // layer first, so it will be the top layer. BoxWhiskerLayer *actualLayer = c->addBoxLayer(DoubleArray(actualStartDate, sizeof(actualStartDate)/sizeof(actualStartDate[0])), DoubleArray( actualEndDate, sizeof(actualEndDate)/sizeof(actualEndDate[0])), actualColor, "Actual"); // Set the bar height to 8 pixels so they will not block the bottom bar actualLayer->setDataWidth(8); // Add a box-whisker layer to represent the planned schedule date c->addBoxLayer(DoubleArray(startDate, sizeof(startDate)/sizeof(startDate[0])), DoubleArray(endDate, sizeof(endDate)/sizeof(endDate[0])), plannedColor, "Planned")->setBorderColor(Chart::SameAsMainColor); // Add a legend box on the top right corner (595, 60) of the plot area with 8 pt // Arial Bold font. Use a semi-transparent grey (80808080) background. LegendBox *b = c->addLegend(595, 60, false, "arialbd.ttf", 8); b->setAlignment(Chart::TopRight); b->setBackground(0x80808080, -1, 2); // output the chart c->makeChart("layergantt.png"); //free up resources delete c; return 0; }
int main(int argc, char *argv[]) { // 4 data points to represent the cash flow for the Q1 - Q4 double data[] = {230, 140, 220, 330, 150}; // We want to plot a waterfall chart showing the 4 quarters as well as the total const char *labels[] = {"Product 1", "Product 2", "Product 3", "Product 4", "Product 5", "Total"}; // The top side of the bars in a waterfall chart is the accumulated data. We use // the ChartDirector ArrayMath utility to accumulate the data. The "total" is // handled by inserting a zero point at the end before accumulation (after // accumulation it will become the total). ArrayMath boxTop = ArrayMath(DoubleArray(data, sizeof(data)/sizeof(data[0])) ).insert(0, 1).acc(); // The botom side of the bars is just the top side of the previous bar. So we // shifted the top side data to obtain the bottom side data. ArrayMath boxBottom = ArrayMath(boxTop).shift(1, 0); // The last point (total) is different. Its bottom side is always 0. boxBottom.trim(0, sizeof(data) / sizeof(data[0])).insert(0, 1); // Create a XYChart object of size 500 x 280 pixels. Set background color to // light blue (ccccff), with 1 pixel 3D border effect. XYChart *c = new XYChart(500, 290, 0xccccff, 0x000000, 1); // Add a title to the chart using 13 points Arial Bold Itatic font, with white // (ffffff) text on a deep blue (0x80) background c->addTitle("Product Revenue - Year 2004", "arialbi.ttf", 13, 0xffffff )->setBackground(0x000080); // Set the plotarea at (55, 50) and of size 430 x 215 pixels. Use alternative // white/grey background. c->setPlotArea(55, 45, 430, 215, 0xffffff, 0xeeeeee); // Set the labels on the x axis using Arial Bold font c->xAxis()->setLabels(StringArray(labels, sizeof(labels)/sizeof(labels[0])) )->setFontStyle("arialbd.ttf"); // Set the x-axis ticks and grid lines to be between the bars c->xAxis()->setTickOffset(0.5); // Use Arial Bold as the y axis label font c->yAxis()->setLabelStyle("arialbd.ttf"); // Add a title to the y axis c->yAxis()->setTitle("USD (in millions)"); // Add a multi-color box-whisker layer to represent the waterfall bars BoxWhiskerLayer *layer = c->addBoxWhiskerLayer2(boxTop, boxBottom); // Put data labels on the bars to show the cash flow using Arial Bold font layer->setDataLabelFormat("{={top}-{bottom}}M"); layer->setDataLabelStyle("arialbd.ttf")->setAlignment(Chart::Center); // Output the chart c->makeChart("waterfall.png"); //free up resources delete c; return 0; }
//只是一个demo,有内存泄露的 QWidget * Widget::addLineWithErrorSymbols() { // The data with error information double data[] = {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 errData[] = {5, 6, 5.1, 6.5, 6.6, 8, 5.4, 5.1, 4.6, 5.0, 5.2, 6.0, 4.9, 5.6, 4.8, 6.2, 7.4, 7.1, 6.0, 6.6, 7.1, 50.3, 5.5, 7.9, 6.1}; // 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 600 x 300 pixels, with a light grey (eeeeee) background, // black border, 1 pixel 3D border effect and rounded corners. XYChart *c = new XYChart(600, 300, 0xeeeeee, 0x000000, 1); c->setRoundedFrame(0xaafaaf); // Set the plotarea at (55, 55) and of size 520 x 195 pixels, with white (ffffff) background. // Set horizontal and vertical grid lines to grey (cccccc). c->setPlotArea(55, 55, 520, 195, 0xffffff, -1, -1, 0xcccccc, 0xcccccc); // Add a title box to the chart using 15pt Times Bold Italic font. The title is in CDML and // includes embedded images for highlight. The text is on a light grey (dddddd) background, with // glass lighting effect. c->addTitle( "<*block,valign=absmiddle*><*img=star.png*><*img=star.png*> Molecular Temperature Control " "<*img=star.png*><*img=star.png*><*/*>", "timesbi.ttf", 15)->setBackground(0xdddddd, 0, Chart::glassEffect());//增加玻璃效果 // Add a title to the y axis c->yAxis()->setTitle("Temperature"); // Add a title to the x axis using CMDL c->xAxis()->setTitle("<*block,valign=absmiddle*><*img=clock.png*> Elapsed Time (hour)<*/*>"); // Set the labels on the x axis. c->xAxis()->setLabels(StringArray(labels, (int)(sizeof(labels) / sizeof(labels[0])))); // Display 1 out of 3 labels on the x-axis. Show minor ticks for remaining labels. c->xAxis()->setLabelStep(3, 1); // Set the axes width to 2 pixels c->xAxis()->setWidth(2); c->yAxis()->setWidth(2); // Add a line layer to the chart LineLayer *lineLayer = c->addLineLayer(); // Add a blue (0xff) data set to the line layer, with yellow (0xffff80) diamond symbols lineLayer->addDataSet(DoubleArray(data, (int)(sizeof(data) / sizeof(data[0]))), 0x0000ff )->setDataSymbol(Chart::DiamondSymbol, 12, 0xffff80); // Set the line width to 2 pixels lineLayer->setLineWidth(2); // Add a box whisker layer to the chart. Use the upper and lower mark of the box whisker layer // to act as error zones. The upper and lower marks are computed using the ArrayMath object. BoxWhiskerLayer *errLayer = c->addBoxWhiskerLayer(DoubleArray(), DoubleArray(), ArrayMath( DoubleArray(data, (int)(sizeof(data) / sizeof(data[0])))).add(DoubleArray(errData, (int)( sizeof(errData) / sizeof(errData[0])))), ArrayMath(DoubleArray(data, (int)(sizeof(data) / sizeof(data[0])))).sub(DoubleArray(errData, (int)(sizeof(errData) / sizeof(errData[0])))), DoubleArray(data, (int)(sizeof(data) / sizeof(data[0]))), Chart::Transparent, 0xbb6633); // Set the line width to 2 pixels errLayer->setLineWidth(2); // Set the error zone to occupy half the space between the symbols errLayer->setDataGap(0.5); // Add a custom CDML text at the bottom right of the plot area as the logo c->addText(575, 247, "<*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("errline.png"); QWidget * _w= new QWidget(); QChartViewer * _v = new QChartViewer(_w); _v->setChart(c); //free up resources //delete c; return _w; }