コード例 #1
0
ファイル: patternarea.cpp プロジェクト: vopl/sp
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;
}
コード例 #2
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;
}
コード例 #3
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;
}
コード例 #4
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;
}