int main(int argc, char *argv[]) { // The data for the pie chart double data[] = {21, 18, 15, 12, 8, 24}; // The labels for the pie chart const char *labels[] = {"Labor", "Licenses", "Taxes", "Legal", "Facilities", "Production"}; // The colors to use for the sectors int colors[] = {0x66aaee, 0xeebb22, 0xbbbbbb, 0x8844ff, 0xdd2222, 0x009900}; // Create a PieChart object of size 600 x 320 pixels. Use a vertical gradient color from light // blue (99ccff) to white (ffffff) spanning the top 100 pixels as background. Set border to grey // (888888). Use rounded corners. Enable soft drop shadow. PieChart *c = new PieChart(600, 320); c->setBackground(c->linearGradientColor(0, 0, 0, 100, 0x99ccff, 0xffffff), 0x888888); c->setRoundedFrame(); c->setDropShadow(); // Add a title using 18pt Times New Roman Bold Italic font. Add 16 pixels top margin to the // title. c->addTitle("Pie Chart With Legend Demonstration", "timesbi.ttf", 18)->setMargin(0, 0, 16, 0); // Set the center of the pie at (160, 165) and the radius to 110 pixels c->setPieSize(160, 165, 110); // Draw the pie in 3D with a pie thickness of 25 pixels c->set3D(25); // Set the pie data and the pie labels c->setData(DoubleArray(data, (int)(sizeof(data) / sizeof(data[0]))), StringArray(labels, (int)( sizeof(labels) / sizeof(labels[0])))); // Set the sector colors c->setColors(Chart::DataColor, IntArray(colors, (int)(sizeof(colors) / sizeof(colors[0])))); // Use local gradient shading for the sectors c->setSectorStyle(Chart::LocalGradientShading); // Use the side label layout method, with the labels positioned 16 pixels from the pie bounding // box c->setLabelLayout(Chart::SideLayout, 16); // Show only the sector number as the sector label c->setLabelFormat("{={sector}+1}"); // Set the sector label style to Arial Bold 10pt, with a dark grey (444444) border c->setLabelStyle("arialbd.ttf", 10)->setBackground(Chart::Transparent, 0x444444); // Add a legend box, with the center of the left side anchored at (330, 175), and using 10pt // Arial Bold Italic font LegendBox *b = c->addLegend(330, 175, true, "arialbi.ttf", 10); b->setAlignment(Chart::Left); // Set the legend box border to dark grey (444444), and with rounded conerns b->setBackground(Chart::Transparent, 0x444444); b->setRoundedCorners(); // Set the legend box margin to 16 pixels, and the extra line spacing between the legend entries // as 5 pixels b->setMargin(16); b->setKeySpacing(0, 5); // Set the legend box icon to have no border (border color same as fill color) b->setKeyBorder(Chart::SameAsMainColor); // Set the legend text to show the sector number, followed by a 120 pixels wide block showing // the sector label, and a 40 pixels wide block showing the percentage b->setText( "<*block,valign=top*>{={sector}+1}.<*advanceTo=22*><*block,width=120*>{label}<*/*>" "<*block,width=40,halign=right*>{percent}<*/*>%"); // Output the chart c->makeChart("legendpie2.png"); //free up resources delete c; return 0; }
//Pyramid 金字塔 QWidget * Widget::addPyramid() { // The data for the pyramid chart double data[] = {156, 123, 211, 179}; // The labels for the pyramid chart const char *labels[] = {"Funds", "Bonds", "Stocks", "Cash"}; // Create a PyramidChart object of size 360 x 360 pixels PyramidChart *c = new PyramidChart(800, 800); // Set the pyramid center at (180, 180), and width x height to 150 x 180 pixels // c->setPyramidSize(180, 180, 150, 300);//设置金字塔 c->setConeSize(280, 180, 150, 300);//设置圆柱形 // Set the funnel center at (200, 210), and width x height to 150 x 300 pixels // c->setFunnelSize(200, 210, 150, 300);//设置漏斗形状 // Set the pyramid data and labels c->setData(DoubleArray(data, (int)(sizeof(data) / sizeof(data[0]))), StringArray(labels, (int)( sizeof(labels) / sizeof(labels[0])))); // Add labels at the center of the pyramid layers using Arial Bold font. The labels will have // two lines showing the layer name and percentage. c->setCenterLabel("{label}\n{percent}%", "arialbd.ttf"); // Set the elevation to 30 degrees.rotate 70 c->setViewAngle(30,70); // The colors for the pyramid layers int colors[] = {0x66aaee, 0xeebb22, 0xcccccc, 0xcc88ff}; // Set the layer colors to the given colors c->setColors(Chart::DataColor, IntArray(colors, (int)(sizeof(colors) / sizeof(colors[0])))); // Leave 1% gaps between layers c->setLayerGap(0.01); // Add labels at the center of the pyramid layers using Arial Bold font. The labels will show // the percentage of the layers. c->setCenterLabel("{percent}%", "arialbd.ttf"); // Add labels at the right side of the pyramid layers using Arial Bold font. The labels will // have two lines showing the layer name and value. c->setRightLabel("{label}\nUS$ {value}M", "arialbd.ttf"); //addBox LegendBox *legendBox = c->addLegend(600, 60); legendBox->setBackground(0xeeeeee, 0x888888); legendBox->setRoundedCorners(10, 0, 10, 0); // Add labels at the center of the pyramid layers using Arial Bold font. The labels will show // the percentage of the layers. c->setCenterLabel("{percent}%", "arialbd.ttf"); // Output the chart c->makeChart("simplepyramid.png"); QWidget * _widget= new QWidget(); QChartViewer * _v= new QChartViewer(_widget); _v->setChart(c); return _widget; }
int main(int argc, char *argv[]) { // In this example, the data points are unevenly spaced on the x-axis double dataY[] = {4.7, 4.7, 6.6, 2.2, 4.7, 4.0, 4.0, 5.1, 4.5, 4.5, 6.8, 4.5, 4, 2.1, 3, 2.5, 2.5, 3.1}; double dataX[] = {Chart::chartTime(1999, 7, 1), Chart::chartTime(2000, 1, 1), Chart::chartTime( 2000, 2, 1), Chart::chartTime(2000, 4, 1), Chart::chartTime(2000, 5, 8), Chart::chartTime( 2000, 7, 5), Chart::chartTime(2001, 3, 5), Chart::chartTime(2001, 4, 7), Chart::chartTime( 2001, 5, 9), Chart::chartTime(2002, 2, 4), Chart::chartTime(2002, 4, 4), Chart::chartTime( 2002, 5, 8), Chart::chartTime(2002, 7, 7), Chart::chartTime(2002, 8, 30), Chart::chartTime( 2003, 1, 2), Chart::chartTime(2003, 2, 16), Chart::chartTime(2003, 11, 6), Chart::chartTime( 2004, 1, 4)}; // Data points are assigned different symbols based on point type double pointType[] = {0, 1, 0, 1, 2, 1, 0, 0, 1, 1, 2, 2, 1, 0, 2, 1, 2, 0}; // Create a XYChart object of size 480 x 320 pixels. Use a vertical gradient color from pale // blue (e8f0f8) to sky blue (aaccff) spanning half the chart height as background. Set border // to blue (88aaee). Use rounded corners. Enable soft drop shadow. XYChart *c = new XYChart(480, 320); c->setBackground(c->linearGradientColor(0, 0, 0, c->getHeight() / 2, 0xe8f0f8, 0xaaccff), 0x88aaee); c->setRoundedFrame(); c->setDropShadow(); // Add a title to the chart using 15 points Arial Italic font. Set top/bottom margins to 12 // pixels. TextBox *title = c->addTitle("Multi-Symbol Line Chart Demo", "ariali.ttf", 15); title->setMargin(0, 0, 12, 12); // Tentatively set the plotarea to 50 pixels from the left edge to allow for the y-axis, and to // just under the title. Set the width to 65 pixels less than the chart width, and the height to // reserve 90 pixels at the bottom for the x-axis and the legend box. Use pale blue (e8f0f8) // background, transparent border, and grey (888888) dotted horizontal and vertical grid lines. c->setPlotArea(50, title->getHeight(), c->getWidth() - 65, c->getHeight() - title->getHeight() - 90, 0xe8f0f8, -1, Chart::Transparent, c->dashLineColor(0x888888, Chart::DotLine), -1); // Add a legend box where the bottom-center is anchored to the 12 pixels above the bottom-center // of the chart. Use horizontal layout and 8 points Arial font. LegendBox *legendBox = c->addLegend(c->getWidth() / 2, c->getHeight() - 12, false, "arialbd.ttf", 8); legendBox->setAlignment(Chart::BottomCenter); // Set the legend box background and border to pale blue (e8f0f8) and bluish grey (445566) legendBox->setBackground(0xe8f0f8, 0x445566); // Use rounded corners of 5 pixel radius for the legend box legendBox->setRoundedCorners(5); // Set the y axis label format to display a percentage sign c->yAxis()->setLabelFormat("{value}%"); // Set y-axis title to use 10 points Arial Bold Italic font c->yAxis()->setTitle("Axis Title Placeholder", "arialbi.ttf", 10); // Set axis labels to use Arial Bold font c->yAxis()->setLabelStyle("arialbd.ttf"); c->xAxis()->setLabelStyle("arialbd.ttf"); // We add the different data symbols using scatter layers. The scatter layers are added before // the line layer to make sure the data symbols stay on top of the line layer. // We select the points with pointType = 0 (the non-selected points will be set to NoValue), and // use yellow (ffff00) 15 pixels high 5 pointed star shape symbols for the points. (This example // uses both x and y coordinates. For charts that have no x explicitly coordinates, use an empty // array as dataX.) c->addScatterLayer(DoubleArray(dataX, (int)(sizeof(dataX) / sizeof(dataX[0]))), ArrayMath( DoubleArray(dataY, (int)(sizeof(dataY) / sizeof(dataY[0])))).selectEQZ(DoubleArray( pointType, (int)(sizeof(pointType) / sizeof(pointType[0]))), Chart::NoValue), "Point Type 0", Chart::StarShape(5), 15, 0xffff00); // Similar to above, we select the points with pointType - 1 = 0 and use green (ff00) 13 pixels // high six-sided polygon as symbols. c->addScatterLayer(DoubleArray(dataX, (int)(sizeof(dataX) / sizeof(dataX[0]))), ArrayMath( DoubleArray(dataY, (int)(sizeof(dataY) / sizeof(dataY[0])))).selectEQZ(ArrayMath( DoubleArray(pointType, (int)(sizeof(pointType) / sizeof(pointType[0])))).sub(1), Chart::NoValue), "Point Type 1", Chart::PolygonShape(6), 13, 0x00ff00); // Similar to above, we select the points with pointType - 2 = 0 and use red (ff0000) 13 pixels // high X shape as symbols. c->addScatterLayer(DoubleArray(dataX, (int)(sizeof(dataX) / sizeof(dataX[0]))), ArrayMath( DoubleArray(dataY, (int)(sizeof(dataY) / sizeof(dataY[0])))).selectEQZ(ArrayMath( DoubleArray(pointType, (int)(sizeof(pointType) / sizeof(pointType[0])))).sub(2), Chart::NoValue), "Point Type 2", Chart::Cross2Shape(), 13, 0xff0000); // Finally, add a blue (0000ff) line layer with line width of 2 pixels LineLayer *layer = c->addLineLayer(DoubleArray(dataY, (int)(sizeof(dataY) / sizeof(dataY[0]))), 0x0000ff); layer->setXData(DoubleArray(dataX, (int)(sizeof(dataX) / sizeof(dataX[0])))); layer->setLineWidth(2); // Adjust the plot area size, such that the bounding box (inclusive of axes) is 10 pixels from // the left edge, just below the title, 25 pixels from the right edge, and 8 pixels above the // legend box. c->packPlotArea(10, title->getHeight(), c->getWidth() - 25, c->layoutLegend()->getTopY() - 8); // Output the chart c->makeChart("multisymbolline.png"); //free up resources delete c; return 0; }
int main(int argc, char *argv[]) { // The data for the pie chart double data[] = {25, 18, 15, 12, 8, 30, 35}; // The labels for the pie chart const char *labels[] = {"Labor", "Licenses", "Taxes", "Legal", "Insurance", "Facilities", "Production"}; // Create a PieChart object of size 600 x 320 pixels. Set background color to // brushed silver, with a 2 pixel 3D border. Use rounded corners of 20 pixels // radius. PieChart *c = new PieChart(600, 320, Chart::brushedSilverColor(), Chart::Transparent, 2); c->setRoundedFrame(0xffffff, 20); // Add a title using 18 pts Times New Roman Bold Italic font. #Set top/bottom // margins to 8 pixels. TextBox *title = c->addTitle("Donut Chart Demonstration", "timesbi.ttf", 18); title->setMargin(0, 0, 8, 8); // Add a 2 pixels wide separator line just under the title c->addLine(10, title->getHeight(), c->getWidth() - 11, title->getHeight(), Chart::LineColor, 2); // Set donut center at (160, 175), and outer/inner radii as 110/55 pixels c->setDonutSize(160, 175, 110, 55); // Set the pie data and the pie labels c->setData(DoubleArray(data, sizeof(data)/sizeof(data[0])), StringArray(labels, sizeof(labels)/sizeof(labels[0]))); // Use ring shading effect for the sectors c->setSectorStyle(Chart::RingShading); // Use the side label layout method, with the labels positioned 16 pixels from // the donut bounding box c->setLabelLayout(Chart::SideLayout, 16); // Show only the sector number as the sector label c->setLabelFormat("{={sector}+1}"); // Set the sector label style to Arial Bold 10pt, with a dark grey (444444) // border c->setLabelStyle("arialbd.ttf", 10)->setBackground(Chart::Transparent, 0x444444); // Add a legend box, with the center of the left side anchored at (330, 175), and // using 10 pts Arial Bold Italic font LegendBox *b = c->addLegend(330, 175, true, "arialbi.ttf", 10); b->setAlignment(Chart::Left); // Set the legend box border to dark grey (444444), and with rounded conerns b->setBackground(Chart::Transparent, 0x444444); b->setRoundedCorners(); // Set the legend box margin to 16 pixels, and the extra line spacing between the // legend entries as 5 pixels b->setMargin(16); b->setKeySpacing(0, 5); // Set the legend text to show the sector number, followed by a 120 pixels wide // block showing the sector label, and a 40 pixels wide block showing the // percentage b->setText( "<*block,valign=top*>{={sector}+1}.<*advanceTo=22*><*block,width=120*>" "{label}<*/*><*block,width=40,halign=right*>{percent}<*/*>%"); // Output the chart c->makeChart("donut.jpg"); //free up resources delete c; return 0; }