コード例 #1
0
int main(int argc, char *argv[])
{
    // The XYZ points for the bubble chart
    double dataX0[] = {170, 300, 1000, 1700};
    double dataY0[] = {16, 69, 16, 75};
    double dataZ0[] = {52, 105, 88, 140};

    double dataX1[] = {500, 1000, 1300};
    double dataY1[] = {40, 58, 85};
    double dataZ1[] = {140, 202, 84};

    // Create a XYChart object of size 540 x 480 pixels
    XYChart *c = new XYChart(540, 480);

    // Set the plotarea at (70, 65) and of size 400 x 350 pixels. Turn on both
    // horizontal and vertical grid lines with light grey color (0xc0c0c0)
    c->setPlotArea(70, 65, 400, 350, -1, -1, Chart::Transparent, 0xc0c0c0, -1);

    // Add a legend box at (70, 30) (top of the chart) with horizontal layout. Use 12
    // pts Times Bold Italic font. Set the background and border color to
    // Transparent.
    c->addLegend(70, 30, false, "timesbi.ttf", 12)->setBackground(Chart::Transparent)
        ;

    // Add a title to the chart using 18 pts Times Bold Itatic font.
    c->addTitle("Product Comparison Chart", "timesbi.ttf", 18);

    // Add titles to the axes using 12 pts Arial Bold Italic font
    c->yAxis()->setTitle("Capacity (tons)", "arialbi.ttf", 12);
    c->xAxis()->setTitle("Range (miles)", "arialbi.ttf", 12);

    // Set the axes line width to 3 pixels
    c->xAxis()->setWidth(3);
    c->yAxis()->setWidth(3);

    // Add (dataX0, dataY0) as a scatter layer with red (ff3333) glass spheres, where
    // the sphere size is modulated by dataZ0. This creates a bubble effect.
    c->addScatterLayer(DoubleArray(dataX0, sizeof(dataX0)/sizeof(dataX0[0])),
        DoubleArray(dataY0, sizeof(dataY0)/sizeof(dataY0[0])), "Technology AAA",
        Chart::GlassSphereShape, 15, 0xff3333)->setSymbolScale(DoubleArray(dataZ0,
        sizeof(dataZ0)/sizeof(dataZ0[0])));

    // Add (dataX1, dataY1) as a scatter layer with blue (0000ff) glass spheres,
    // where the sphere size is modulated by dataZ1. This creates a bubble effect.
    c->addScatterLayer(DoubleArray(dataX1, sizeof(dataX1)/sizeof(dataX1[0])),
        DoubleArray(dataY1, sizeof(dataY1)/sizeof(dataY1[0])), "Technology BBB",
        Chart::GlassSphereShape, 15, 0x0000ff)->setSymbolScale(DoubleArray(dataZ1,
        sizeof(dataZ1)/sizeof(dataZ1[0])));

    // Output the chart
    c->makeChart("threedbubble.png");

    //free up resources
    delete c;
    return 0;
}
int main(int argc, char *argv[])
{
    // The XY points for the scatter chart
    double dataX[] = {200, 400, 300, 250, 500};
    double dataY[] = {40, 100, 50, 150, 250};

    // The custom symbols for the points
    const char *symbols[] = {"robot1.png", "robot2.png", "robot3.png", "robot4.png",
        "robot5.png"};

    // Create a XYChart object of size 450 x 400 pixels
    XYChart *c = new XYChart(450, 400);

    // Set the plotarea at (55, 40) and of size 350 x 300 pixels, with a light grey
    // border (0xc0c0c0). Turn on both horizontal and vertical grid lines with light
    // grey color (0xc0c0c0)
    c->setPlotArea(55, 40, 350, 300, -1, -1, 0xc0c0c0, 0xc0c0c0, -1);

    // Add a title to the chart using 18 pts Times Bold Itatic font.
    c->addTitle("Battle Robots", "timesbi.ttf", 18);

    // Add a title to the y axis using 12 pts Arial Bold Italic font
    c->yAxis()->setTitle("Speed (km/s)", "arialbi.ttf", 12);

    // Add a title to the y axis using 12 pts Arial Bold Italic font
    c->xAxis()->setTitle("Range (km)", "arialbi.ttf", 12);

    // Set the axes line width to 3 pixels
    c->xAxis()->setWidth(3);
    c->yAxis()->setWidth(3);

    // Add each point of the data as a separate scatter layer, so that they can have
    // a different symbol
    int i;
    for(i = 0; i < sizeof(dataX) / sizeof(dataX[0]); ++i) {
        double coor1[] = {dataX[i]};
        double coor2[] = {dataY[i]};
        c->addScatterLayer(DoubleArray(coor1, sizeof(coor1)/sizeof(coor1[0])),
            DoubleArray(coor2, sizeof(coor2)/sizeof(coor2[0])))->getDataSet(0
            )->setDataSymbol(symbols[i]);
    }

    // Output the chart
    c->makeChart("scattersymbols.png");

    //free up resources
    delete c;
    return 0;
}
コード例 #3
0
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;
}
コード例 #4
0
int main(int argc, char *argv[])
{
    // The XYZ points for the bubble chart
    double dataX0[] = {150, 300, 1000, 1700};
    double dataY0[] = {12, 60, 25, 65};
    double dataZ0[] = {20, 50, 50, 85};

    double dataX1[] = {500, 1000, 1300};
    double dataY1[] = {35, 50, 75};
    double dataZ1[] = {30, 55, 95};

    // 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 a light grey
    // border (0xc0c0c0). Turn on both horizontal and vertical grid lines with light
    // grey color (0xc0c0c0)
    c->setPlotArea(55, 65, 350, 300, -1, -1, 0xc0c0c0, 0xc0c0c0, -1);

    // Add a legend box at (50, 30) (top of the chart) with horizontal layout. Use 12
    // pts Times Bold Italic font. Set the background and border color to
    // Transparent.
    c->addLegend(50, 30, false, "timesbi.ttf", 12)->setBackground(Chart::Transparent)
    ;

    // Add a title to the chart using 18 pts Times Bold Itatic font.
    c->addTitle("Product Comparison Chart", "timesbi.ttf", 18);

    // Add a title to the y axis using 12 pts Arial Bold Italic font
    c->yAxis()->setTitle("Capacity (tons)", "arialbi.ttf", 12);

    // Add a title to the x axis using 12 pts Arial Bold Italic font
    c->xAxis()->setTitle("Range (miles)", "arialbi.ttf", 12);

    // Set the axes line width to 3 pixels
    c->xAxis()->setWidth(3);
    c->yAxis()->setWidth(3);

    // Add (dataX0, dataY0) as a scatter layer with semi-transparent red (0x80ff3333)
    // circle symbols, where the circle size is modulated by dataZ0. This creates a
    // bubble effect.
    c->addScatterLayer(DoubleArray(dataX0, sizeof(dataX0)/sizeof(dataX0[0])),
                       DoubleArray(dataY0, sizeof(dataY0)/sizeof(dataY0[0])), "Technology AAA",
                       Chart::CircleSymbol, 9, 0x80ff3333, 0x80ff3333)->setSymbolScale(DoubleArray(
                                   dataZ0, sizeof(dataZ0)/sizeof(dataZ0[0])));

    // Add (dataX1, dataY1) as a scatter layer with semi-transparent green
    // (0x803333ff) circle symbols, where the circle size is modulated by dataZ1.
    // This creates a bubble effect.
    c->addScatterLayer(DoubleArray(dataX1, sizeof(dataX1)/sizeof(dataX1[0])),
                       DoubleArray(dataY1, sizeof(dataY1)/sizeof(dataY1[0])), "Technology BBB",
                       Chart::CircleSymbol, 9, 0x803333ff, 0x803333ff)->setSymbolScale(DoubleArray(
                                   dataZ1, sizeof(dataZ1)/sizeof(dataZ1[0])));

    // Output the chart
    c->makeChart("bubble.png");

    //free up resources
    delete c;
    return 0;
}
コード例 #5
0
ファイル: multisymbolline.cpp プロジェクト: vopl/sp
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[] = {chartTime(1999, 7, 1), chartTime(2000, 1, 1), chartTime(2000,
        2, 1), chartTime(2000, 4, 1), chartTime(2000, 5, 8), chartTime(2000, 7, 5),
        chartTime(2001, 3, 5), chartTime(2001, 4, 7), chartTime(2001, 5, 9),
        chartTime(2002, 2, 4), chartTime(2002, 4, 4), chartTime(2002, 5, 8),
        chartTime(2002, 7, 7), chartTime(2002, 8, 30), chartTime(2003, 1, 2),
        chartTime(2003, 2, 16), chartTime(2003, 11, 6), 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 600 x 300 pixels, with a light purple (ffccff)
    // background, black border, 1 pixel 3D border effect and rounded corners.
    XYChart *c = new XYChart(600, 300, 0xffccff, 0x000000, 1);
    c->setRoundedFrame();

    // Set the plotarea at (55, 58) and of size 520 x 195 pixels, with white (ffffff)
    // background. Set horizontal and vertical grid lines to grey (cccccc).
    c->setPlotArea(55, 58, 520, 195, 0xffffff, -1, -1, 0xcccccc, 0xcccccc);

    // Add a legend box at (55, 30) (top of the chart) with horizontal layout. Use 10
    // pts Arial Bold Italic font. Set the background and border color to
    // Transparent.
    c->addLegend(55, 30, false, "arialbi.ttf", 10)->setBackground(Chart::Transparent)
        ;

    // Add a title box to the chart using 15 pts Times Bold Italic font. The text is
    // white (ffffff) on a purple (400040) background, with soft lighting effect from
    // the right side.
    c->addTitle("Multi-Symbol Line Chart Demo", "timesbi.ttf", 15, 0xffffff
        )->setBackground(0x400040, -1, Chart::softLighting(Chart::Right));

    // Set the y axis label format to display a percentage sign
    c->yAxis()->setLabelFormat("{value}%");

    // Set axis titles to use 9pt Arial Bold Italic font
    c->yAxis()->setTitle("Axis Title Placeholder", "arialbi.ttf", 9);
    c->xAxis()->setTitle("Axis Title Placeholder", "arialbi.ttf", 9);

    // 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, sizeof(dataX)/sizeof(dataX[0])), ArrayMath(
        DoubleArray(dataY, sizeof(dataY)/sizeof(dataY[0]))).selectEQZ(DoubleArray(
        pointType, 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, sizeof(dataX)/sizeof(dataX[0])), ArrayMath(
        DoubleArray(dataY, sizeof(dataY)/sizeof(dataY[0]))).selectEQZ(ArrayMath(
        DoubleArray(pointType, 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, sizeof(dataX)/sizeof(dataX[0])), ArrayMath(
        DoubleArray(dataY, sizeof(dataY)/sizeof(dataY[0]))).selectEQZ(ArrayMath(
        DoubleArray(pointType, 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,
        sizeof(dataY)/sizeof(dataY[0])), 0x0000ff);
    layer->setXData(DoubleArray(dataX, sizeof(dataX)/sizeof(dataX[0])));
    layer->setLineWidth(2);

    // output the chart
    c->makeChart("multisymbolline.png");

    //free up resources
    delete c;
    return 0;
}
コード例 #6
0
ファイル: paramcurve.cpp プロジェクト: BIbiLion/LSWuqiankun
int main(int argc, char *argv[])
{
    // The XY data of the first data series
    double dataX0[] = {10, 35, 17, 4, 22, 29, 45, 52, 63, 39};
    double dataY0[] = {2.0, 3.2, 2.7, 1.2, 2.8, 2.9, 3.1, 3.0, 2.3, 3.3};

    // The XY data of the second data series
    double dataX1[] = {30, 35, 17, 4, 22, 59, 43, 52, 63, 39};
    double dataY1[] = {1.0, 1.3, 0.7, 0.6, 0.8, 3.0, 1.8, 2.3, 3.4, 1.5};

    // The XY data of the third data series
    double dataX2[] = {28, 35, 15, 10, 22, 60, 46, 64, 39};
    double dataY2[] = {2.0, 2.2, 1.2, 0.4, 1.8, 2.7, 2.4, 2.8, 2.4};

    // Create a XYChart object of size 540 x 480 pixels
    XYChart *c = new XYChart(540, 480);

    // Set the plotarea at (70, 65) and of size 400 x 350 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(70, 65, 400, 350, 0xffffff, -1, 0xc0c0c0, 0xc0c0c0, -1);

    // Add a legend box with the top center point anchored at (270, 30). Use horizontal layout. Use
    // 10pt Arial Bold Italic font. Set the background and border color to Transparent.
    LegendBox *legendBox = c->addLegend(270, 30, false, "arialbi.ttf", 10);
    legendBox->setAlignment(Chart::TopCenter);
    legendBox->setBackground(Chart::Transparent, Chart::Transparent);

    // Add a title to the chart using 18 point Times Bold Itatic font.
    c->addTitle("Parametric Curve Fitting", "timesbi.ttf", 18);

    // Add titles to the axes using 12pt Arial Bold Italic font
    c->yAxis()->setTitle("Axis Title Placeholder", "arialbi.ttf", 12);
    c->xAxis()->setTitle("Axis Title Placeholder", "arialbi.ttf", 12);

    // Set the axes line width to 3 pixels
    c->yAxis()->setWidth(3);
    c->xAxis()->setWidth(3);

    // Add a scatter layer using (dataX0, dataY0)
    c->addScatterLayer(DoubleArray(dataX0, (int)(sizeof(dataX0) / sizeof(dataX0[0]))), DoubleArray(
        dataY0, (int)(sizeof(dataY0) / sizeof(dataY0[0]))), "Polynomial", Chart::GlassSphere2Shape,
        11, 0xff0000);

    // Add a degree 2 polynomial trend line layer for (dataX0, dataY0)
    TrendLayer *trend0 = c->addTrendLayer(DoubleArray(dataX0, (int)(sizeof(dataX0) / sizeof(dataX0[0
        ]))), DoubleArray(dataY0, (int)(sizeof(dataY0) / sizeof(dataY0[0]))), 0xff0000);
    trend0->setLineWidth(3);
    trend0->setRegressionType(Chart::PolynomialRegression(2));

    // Add a scatter layer for (dataX1, dataY1)
    c->addScatterLayer(DoubleArray(dataX1, (int)(sizeof(dataX1) / sizeof(dataX1[0]))), DoubleArray(
        dataY1, (int)(sizeof(dataY1) / sizeof(dataY1[0]))), "Exponential", Chart::GlassSphere2Shape,
        11, 0x00aa00);

    // Add an exponential trend line layer for (dataX1, dataY1)
    TrendLayer *trend1 = c->addTrendLayer(DoubleArray(dataX1, (int)(sizeof(dataX1) / sizeof(dataX1[0
        ]))), DoubleArray(dataY1, (int)(sizeof(dataY1) / sizeof(dataY1[0]))), 0x00aa00);
    trend1->setLineWidth(3);
    trend1->setRegressionType(Chart::ExponentialRegression);

    // Add a scatter layer using (dataX2, dataY2)
    c->addScatterLayer(DoubleArray(dataX2, (int)(sizeof(dataX2) / sizeof(dataX2[0]))), DoubleArray(
        dataY2, (int)(sizeof(dataY2) / sizeof(dataY2[0]))), "Logarithmic", Chart::GlassSphere2Shape,
        11, 0x0000ff);

    // Add a logarithmic trend line layer for (dataX2, dataY2)
    TrendLayer *trend2 = c->addTrendLayer(DoubleArray(dataX2, (int)(sizeof(dataX2) / sizeof(dataX2[0
        ]))), DoubleArray(dataY2, (int)(sizeof(dataY2) / sizeof(dataY2[0]))), 0x0000ff);
    trend2->setLineWidth(3);
    trend2->setRegressionType(Chart::LogarithmicRegression);

    // Output the chart
    c->makeChart("paramcurve.png");

    //free up resources
    delete c;
    return 0;
}
コード例 #7
0
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[])
{
    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;
}