int main(int argc, char *argv[]) { // The data for the area chart double data[] = {3.0, 2.8, 4.0, 5.5, 7.5, 6.8, 5.4, 6.0, 5.0, 6.2, 7.5, 6.5, 7.5, 8.1, 6.0, 5.5, 5.3, 3.5, 5.0, 6.6, 5.6, 4.8, 5.2, 6.5, 6.2}; // The labels for the area 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 300 x 180 pixels. Set the background to pale // yellow (0xffffa0) with a black border (0x0) XYChart *c = new XYChart(300, 180, 0xffffa0, 0x000000); // Set the plotarea at (45, 35) and of size 240 x 120 pixels. Set the background // to white (0xffffff). Set both horizontal and vertical grid lines to black // (&H0&) dotted lines (pattern code 0x0103) c->setPlotArea(45, 35, 240, 120, 0xffffff, -1, -1, c->dashLineColor(0x000000, 0x000103), c->dashLineColor(0x000000, 0x000103)); // Add a title to the chart using 10 pts Arial Bold font. Use a 1 x 2 bitmap // pattern as the background. Set the border to black (0x0). int pattern1[] = {0xb0b0f0, 0xe0e0ff}; c->addTitle("Snow Percipitation (Dec 12)", "arialbd.ttf", 10)->setBackground( c->patternColor(IntArray(pattern1, sizeof(pattern1)/sizeof(pattern1[0])), 2), 0x000000); // Add a title to the y axis c->yAxis()->setTitle("mm per hour"); // 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 an area layer to the chart AreaLayer *layer = c->addAreaLayer(); // Load a snow pattern from an external file "snow.png". int snowPattern = c->patternColor("snow.png"); // Add a data set to the area layer using the snow pattern as the fill color. Use // deep blue (0x0000ff) as the area border line color (&H0000ff&) layer->addDataSet(DoubleArray(data, sizeof(data)/sizeof(data[0])))->setDataColor( snowPattern, 0x0000ff); // Set the line width to 2 pixels to highlight the line layer->setLineWidth(2); // output the chart c->makeChart("patternarea.png"); //free up resources delete c; return 0; }
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, 45, 47, 34, 42, 49, 63, 62, 73, 59, 56, 50, 64, 60, 67, 67, 58, 59, 73, 77, 84, 82, 80, 84, 89}; double data2[] = {61, 79, 85, 66, 53, 39, 24, 21, 37, 56, 37, 22, 21, 33, 13, 17, 4, 23, 16, 25, 9, 10, 5, 7, 16}; 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 XYChart *c = new XYChart(500, 300); // Set the plotarea at (90, 30) and of size 300 x 240 pixels. c->setPlotArea(90, 30, 300, 240); // Add a legend box at (405, 100) c->addLegend(405, 100); // Add a title to the chart c->addTitle("Daily System Load"); // Add a title to the y axis. Draw the title upright (font angle = 0) c->yAxis()->setTitle("Database\nQueries\n(per sec)")->setFontAngle(0); // Set the labels on the x axis. c->xAxis()->setLabels(StringArray(labels, (int)(sizeof(labels) / sizeof(labels[0])))); // Display 1 out of 2 labels on the x-axis. Show minor ticks for remaining labels. c->xAxis()->setLabelStep(2, 1); // Add an area layer AreaLayer *layer = c->addAreaLayer(); // Draw the area layer in 3D layer->set3D(); // Add the three data sets to the area layer layer->addDataSet(DoubleArray(data0, (int)(sizeof(data0) / sizeof(data0[0]))), -1, "Server # 1") ; layer->addDataSet(DoubleArray(data1, (int)(sizeof(data1) / sizeof(data1[0]))), -1, "Server # 2") ; layer->addDataSet(DoubleArray(data2, (int)(sizeof(data2) / sizeof(data2[0]))), -1, "Server # 3") ; // Output the chart c->makeChart("threedstackarea.png"); //free up resources delete c; return 0; }
int main(int argc, char *argv[]) { // The data for the area 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 area chart double 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 320 x 320 pixels XYChart *c = new XYChart(320, 320); // Swap the x and y axis to become a rotated chart c->swapXY(); // Set the y axis on the top side (right + rotated = top) c->setYAxisOnRight(); // Reverse the x axis so it is pointing downwards c->xAxis()->setReverse(); // Set the plotarea at (50, 50) and of size 200 x 200 pixels. Enable horizontal and vertical // grids by setting their colors to grey (0xc0c0c0). c->setPlotArea(50, 50, 250, 250)->setGridColor(0xc0c0c0, 0xc0c0c0); // Add a line chart layer using the given data c->addAreaLayer(DoubleArray(data, (int)(sizeof(data) / sizeof(data[0]))), c->gradientColor(50, 0, 300, 0, 0xffffff, 0x0000ff)); // Set the labels on the x axis. Append "m" after the value to show the unit. c->xAxis()->setLabels(DoubleArray(labels, (int)(sizeof(labels) / sizeof(labels[0]))), "{value} m"); // Display 1 out of 3 labels. c->xAxis()->setLabelStep(3); // Add a title to the x axis c->xAxis()->setTitle("Depth"); // Add a title to the y axis c->yAxis()->setTitle("Carbon Dioxide Concentration (ppm)"); // Output the chart c->makeChart("rotatedarea.png"); //free up resources delete c; return 0; }
int main(int argc, char *argv[]) { // The data for the area 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 area 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 300 x 300 pixels XYChart *c = new XYChart(300, 300); // Set the plotarea at (45, 30) and of size 200 x 200 pixels c->setPlotArea(45, 30, 200, 200); // Add a title to the chart using 12 pts Arial Bold Italic font c->addTitle("Daily Server Utilization", "arialbi.ttf", 12); // Add a title to the y axis c->yAxis()->setTitle("MBytes"); // Add a title to the x axis c->xAxis()->setTitle("June 12, 2001"); // Add a green (0x00ff00) 3D area chart layer using the give data c->addAreaLayer(DoubleArray(data, sizeof(data)/sizeof(data[0])), 0x00ff00 )->set3D(); // 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); // Output the chart c->makeChart("threedarea.png"); //free up resources delete c; return 0; }
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 data for the area 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 area 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 360 pixels, with a brushed silver // background, 1 pixel 3D border effect, rounded corners and soft drop shadow. XYChart *c = new XYChart(600, 360, Chart::brushedSilverColor(), Chart::Transparent, 1); c->setRoundedFrame(); c->setDropShadow(); // Add a title box to the chart using 18 pts Times Bold Italic font. TextBox *title = c->addTitle( "<*block,valign=absmiddle*><*img=star.png*><*img=star.png*> Performance " "Enhancer <*img=star.png*><*img=star.png*><*/*>", "timesbi.ttf", 18); // // Use a text box with a depressed 3D border to create the inner depressed region // // The width of the frame border int frameWidth = 5; // Set the depressed region position TextBox *contentBox = c->addText(frameWidth, title->getHeight(), ""); contentBox->setSize(c->getDrawArea()->getWidth() - 1 - frameWidth * 2, c->getDrawArea()->getHeight() - title->getHeight() - frameWidth - 1); // Use -1 as the rasied effect to create a depressed region contentBox->setBackground(Chart::Transparent, Chart::Transparent, -1); // Set rounded corners, and put the text box at the back of the chart contentBox->setRoundedCorners(10); contentBox->setZOrder(Chart::ChartBackZ); // Tentatively set the plotarea to 50 pixels from the left depressed edge, and 25 // pixels under the top depressed edge. Set the width to 75 pixels less than the // depressed region width, and the height to 75 pixels less than the depressed // region height. Use white (ffffff) background, transparent border, and grey // (cccccc) horizontal and vertical grid lines. PlotArea *plotArea = c->setPlotArea(50 + contentBox->getLeftX(), contentBox->getTopY() + 25, contentBox->getWidth() - 75, contentBox->getHeight() - 75, 0xffffff, -1, -1, 0xcccccc, -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 using a gradient color that changes vertically // from semi-transparent red (60ff0000) to semi-transparent white (60ffffff) c->addAreaLayer(DoubleArray(data, sizeof(data)/sizeof(data[0])), c->linearGradientColor(0, contentBox->getTopY() + 20, 0, contentBox->getTopY( ) + contentBox->getHeight() - 50, 0x60ff0000, 0x60ffffff)); // Adjust the plot area size, such that the bounding box (inclusive of axes) is // 15 pixels from the left depressed edge, 25 pixels below the top depressed // edge, 25 pixels from the right depressed edge, and 15 pixels above the bottom // depressed edge. c->packPlotArea(contentBox->getLeftX() + 15, contentBox->getTopY() + 25, contentBox->getLeftX() + contentBox->getWidth() - 25, contentBox->getTopY() + contentBox->getHeight() - 15); // Add a custom CDML text with the bottom right corner is anchored to the bootom // right corner of the plot area, with 5 pixels margin. c->addText(plotArea->getLeftX() + plotArea->getWidth() - 5, plotArea->getTopY() + plotArea->getHeight() - 5, "<*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("enhancedarea.jpg"); //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 data for the 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}; // The labels for the bottom x axis. Note the "-" means a minor tick. const char *labels0[] = {"0\nJun 4", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "0\nJun 5"}; // The labels for the top x axis. Note that "-" means a minor tick. const char *labels1[] = {"Jun 3\n12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "Jun 4\n0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}; // Create a XYChart object of size 310 x 310 pixels XYChart *c = new XYChart(310, 310); // Set the plotarea at (50, 50) and of size 200 x 200 pixels c->setPlotArea(50, 50, 200, 200); // Add a title to the primary (left) y axis c->yAxis()->setTitle("US Dollars"); // Set the tick length to -4 pixels (-ve means ticks inside the plot area) c->yAxis()->setTickLength(-4); // Add a title to the secondary (right) y axis c->yAxis2()->setTitle("HK Dollars (1 USD = 7.8 HKD)"); // Set the tick length to -4 pixels (-ve means ticks inside the plot area) c->yAxis2()->setTickLength(-4); // Synchronize the y-axis such that y2 = 7.8 x y1 c->syncYAxis(7.8); // Add a title to the bottom x axis c->xAxis()->setTitle("Hong Kong Time"); // Set the labels on the x axis. c->xAxis()->setLabels(StringArray(labels0, sizeof(labels0)/sizeof(labels0[0]))); // Display 1 out of 3 labels on the x-axis. Show minor ticks for remaining // labels. c->xAxis()->setLabelStep(3, 1); // Set the major tick length to -4 pixels and minor tick length to -2 pixels (-ve // means ticks inside the plot area) c->xAxis()->setTickLength(-4, -2); // Set the distance between the axis labels and the axis to 6 pixels c->xAxis()->setLabelGap(6); // Add a title to the top x-axis c->xAxis2()->setTitle("New York Time"); // Set the labels on the x axis. c->xAxis2()->setLabels(StringArray(labels1, sizeof(labels1)/sizeof(labels1[0]))); // Display 1 out of 3 labels on the x-axis. Show minor ticks for remaining // labels. c->xAxis2()->setLabelStep(3, 1); // Set the major tick length to -4 pixels and minor tick length to -2 pixels (-ve // means ticks inside the plot area) c->xAxis2()->setTickLength(-4, -2); // Set the distance between the axis labels and the axis to 6 pixels c->xAxis2()->setLabelGap(6); // Add a line layer to the chart with a line width of 2 pixels c->addLineLayer(DoubleArray(data0, sizeof(data0)/sizeof(data0[0])), -1, "Red Transactions")->setLineWidth(2); // Add an area layer to the chart with no area boundary line c->addAreaLayer(DoubleArray(data1, sizeof(data1)/sizeof(data1[0])), -1, "Green Transactions")->setLineWidth(0); // output the chart c->makeChart("dualxaxis.png"); //free up resources delete c; return 0; }
int main(int argc, char *argv[]) { // The data for the chart double data[] = {800, 600, 1000, 1400}; double widths[] = {250, 500, 960, 460}; const char *labels[] = {"Wind", "Hydro", "Coal", "Natural Gas"}; // The colors to use int colors[] = {0x00aa00, 0x66aaee, 0xee6622, 0xffbb00}; // Create a XYChart object of size 500 x 350 pixels XYChart *c = new XYChart(500, 350); // Add a title to the chart using 15 pts Arial Italic font c->addTitle("Energy Generation Breakdown", "ariali.ttf", 15); // Set the plotarea at (60, 60) and of (chart_width - 90) x (chart_height - 100) // in size. Use a vertical gradient color from light blue (f9f9ff) to sky blue // (aaccff) as background. Set grid lines to white (ffffff). int plotAreaBgColor = c->linearGradientColor(0, 60, 0, c->getHeight() - 40, 0xaaccff, 0xf9fcff); c->setPlotArea(60, 60, c->getWidth() - 90, c->getHeight() - 100, plotAreaBgColor, -1, -1, 0xffffff); // Add a legend box at (50, 30) using horizontal layout and transparent // background. c->addLegend(55, 30, false)->setBackground(Chart::Transparent); // Add titles to x/y axes with 10 points Arial Bold font c->xAxis()->setTitle("Mega Watts", "arialbd.ttf", 10); c->yAxis()->setTitle("Cost per MWh (dollars)", "arialbd.ttf", 10); // Set the x axis rounding to false, so that the x-axis will fit the data exactly c->xAxis()->setRounding(false, false); // In ChartDirector, there is no bar layer that can have variable bar widths, but // you may create a bar using an area layer. (A bar can be considered as the area // under a rectangular outline.) So by using a loop to create one bar per area // layer, we can achieve a variable width bar chart. // starting position of current bar double currentX = 0; int i; for(i = 0; i < sizeof(data) / sizeof(data[0]); ++i) { // ending position of current bar double nextX = currentX + widths[i]; // outline of the bar double dataX[] = {currentX, currentX, nextX, nextX}; double dataY[] = {0, data[i], data[i], 0}; // create the area layer to fill the bar AreaLayer *layer = c->addAreaLayer(DoubleArray(dataY, sizeof(dataY)/sizeof(dataY[0])), colors[i], labels[i]); layer->setXData(DoubleArray(dataX, sizeof(dataX)/sizeof(dataX[0]))); // the ending position becomes the starting position of the next bar currentX = nextX; } // Output the chart c->makeChart("varwidthbar.png"); //free up resources delete c; return 0; }