示例#1
0
文件: simpleline.cpp 项目: vopl/sp
int main(int argc, char *argv[])
{
    // The data for the line chart
    double data[] = {30, 28, 40, 55, 75, 68, 54, 60, 50, 62, 75, 65, 75, 91, 60, 55,
        53, 35, 50, 66, 56, 48, 52, 65, 62};

    // The labels for the line 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 250 x 250 pixels
    XYChart *c = new XYChart(250, 250);

    // Set the plotarea at (30, 20) and of size 200 x 200 pixels
    c->setPlotArea(30, 20, 200, 200);

    // Add a line chart layer using the given data
    c->addLineLayer(DoubleArray(data, sizeof(data)/sizeof(data[0])));

    // 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("simpleline.png");

    //free up resources
    delete c;
    return 0;
}
int main(int argc, char *argv[])
{
    // The data for the bar chart
    double data[] = {450, 560, 630, 800, 1100, 1350, 1600, 1950, 2300, 2700};

    // The labels for the bar chart
    const char *labels[] = {"1996", "1997", "1998", "1999", "2000", "2001", "2002",
        "2003", "2004", "2005"};

    // Create a XYChart object of size 600 x 380 pixels. Set background color to
    // brushed silver, with a 2 pixel 3D border. Use rounded corners of 20 pixels
    // radius.
    XYChart *c = new XYChart(600, 380, Chart::brushedSilverColor(),
        Chart::Transparent, 2);

    // Add a title to the chart using 18pts Times Bold Italic font. Set top/bottom
    // margins to 8 pixels.
    c->addTitle("Annual Revenue for Star Tech", "timesbi.ttf", 18)->setMargin(0, 0,
        8, 8);

    // Set the plotarea at (70, 55) and of size 460 x 280 pixels. Use transparent
    // border and black grid lines. Use rounded frame with radius of 20 pixels.
    c->setPlotArea(70, 55, 460, 280, -1, -1, Chart::Transparent, 0x000000);
    c->setRoundedFrame(0xffffff, 20);

    // Add a multi-color bar chart layer using the supplied data. Set cylinder bar
    // shape.
    c->addBarLayer(DoubleArray(data, sizeof(data)/sizeof(data[0])), IntArray(0, 0)
        )->setBarShape(Chart::CircleShape);

    // Set the labels on the x axis.
    c->xAxis()->setLabels(StringArray(labels, sizeof(labels)/sizeof(labels[0])));

    // Show the same scale on the left and right y-axes
    c->syncYAxis();

    // Set the left y-axis and right y-axis title using 10pt Arial Bold font
    c->yAxis()->setTitle("USD (millions)", "arialbd.ttf", 10);
    c->yAxis2()->setTitle("USD (millions)", "arialbd.ttf", 10);

    // Set y-axes to transparent
    c->yAxis()->setColors(Chart::Transparent);
    c->yAxis2()->setColors(Chart::Transparent);

    // Disable ticks on the x-axis by setting the tick color to transparent
    c->xAxis()->setTickColor(Chart::Transparent);

    // Set the label styles of all axes to 8pt Arial Bold font
    c->xAxis()->setLabelStyle("arialbd.ttf", 8);
    c->yAxis()->setLabelStyle("arialbd.ttf", 8);
    c->yAxis2()->setLabelStyle("arialbd.ttf", 8);

    // Output the chart
    c->makeChart("cylinderlightbar.jpg");

    //free up resources
    delete c;
    return 0;
}
示例#3
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;
}
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;
}
示例#5
0
void GraphWidget::drawChart()
{
    XYChart *c = new XYChart(size.width(), size.height() - 100, Chart::Transparent);

    c->setPlotArea(10, 50, c->getWidth() - 65, c->getHeight() - 10, 0x000000, -1, 0xC8C8C8, Chart::Transparent, Chart::Transparent);

    c->setClipping();

    c->getLegend()->setLineStyleKey();
    c->getLegend()->setFontSize(10);

    //遍历查询结果并绘制结果
    int ea_result_count = ea_results.size();
    //设置X轴的label
    for(int i = 0;i < ea_result_count;i++){
        ExchangeRateResult *ea_result = ea_results[i];
        DoubleArray x_data = getXData(i);
        DoubleArray y_data = ea_result->getYData();

        double viewPortStartDate = m_ChartViewer->getValueAtViewPort("x", m_ChartViewer->getViewPortLeft());
        double viewPortEndDate = m_ChartViewer->getValueAtViewPort("x", m_ChartViewer->getViewPortLeft() +
            m_ChartViewer->getViewPortWidth());

        int startIndex = (int)floor(Chart::bSearch(x_data, viewPortStartDate));
        int endIndex = (int)ceil(Chart::bSearch(x_data, viewPortEndDate));
        int noOfPoints = endIndex - startIndex + 1;

        DoubleArray viewPortXData = DoubleArray(x_data.data + startIndex, noOfPoints);
        DoubleArray viewPortYData = DoubleArray(y_data.data + startIndex, noOfPoints);
        //添加图层
        LineLayer *layer = c->addLineLayer();
        layer->setLineWidth(1);
        //设置X轴
        layer->setXData(viewPortXData);
        //设置Y轴
        layer->addDataSet(viewPortYData, ea_result->getColor(), ea_result->getName().toUtf8().data())->setUseYAxis2();
    }
    c->xAxis()->setLabelStyle("arial.ttf", 10);
    c->yAxis2()->setLabelStyle("arial.ttf", 10);
    c->xAxis()->setColors(0xC8C8C8, 0xC8C8C8);
    c->yAxis2()->setColors(0xC8C8C8, 0xC8C8C8);

    m_ChartViewer->syncDateAxisWithViewPort("x", c->xAxis());

    c->yAxis()->setTickDensity(30);
    c->yAxis2()->setTickDensity(30);

    if (!m_ChartViewer->isInMouseMoveEvent())
    {
        trackLineLegend(c, (0 == m_ChartViewer->getChart()) ? c->getPlotArea()->getRightX() :
            m_ChartViewer->getPlotAreaMouseX());
    }
    delete m_ChartViewer->getChart();
    m_ChartViewer->setChart(c);
}
示例#6
0
//
// Draw the chart and display it in the given viewer
//
void TrackAxis::drawChart(QChartViewer *viewer)
{
    // Data for the chart as 2 random data series
    RanSeries r(127);
    DoubleArray data0 = r.getSeries(180, 10, -1.5, 1.5);
    DoubleArray data1 = r.getSeries(180, 150, -15, 15);
    DoubleArray timeStamps = r.getDateSeries(180, Chart::chartTime(2011, 1, 1), 86400);

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

    // Add a title to the chart using 18 pts Times New Roman Bold Italic font
    c->addTitle("Plasma Stabilizer Energy Usage", "timesbi.ttf", 18);

    // Set the plotarea at (50, 55) with width 100 pixels less than chart width, and height 90 pixels
    // less than chart height. Use a vertical gradient from light blue (f0f6ff) to sky blue (a0c0ff)
    // as background. Set border to transparent and grid lines to white (ffffff).
    c->setPlotArea(50, 55, c->getWidth() - 100, c->getHeight() - 90, c->linearGradientColor(0, 55, 0,
        c->getHeight() - 35, 0xf0f6ff, 0xa0c0ff), -1, Chart::Transparent, 0xffffff, 0xffffff);

    // Add a legend box at (50, 25) using horizontal layout. Use 10pts Arial Bold as font. Set the
    // background and border color to Transparent.
    c->addLegend(50, 25, false, "arialbd.ttf", 10)->setBackground(Chart::Transparent);

    // Set axis label style to 8pts Arial Bold
    c->xAxis()->setLabelStyle("arialbd.ttf", 8);
    c->yAxis()->setLabelStyle("arialbd.ttf", 8);
    c->yAxis2()->setLabelStyle("arialbd.ttf", 8);

    // Set the axis stem to transparent
    c->xAxis()->setColors(Chart::Transparent);
    c->yAxis()->setColors(Chart::Transparent);
    c->yAxis2()->setColors(Chart::Transparent);

    // Configure x-axis label format
    c->xAxis()->setMultiFormat(Chart::StartOfYearFilter(), "{value|mm/yyyy} ",
        Chart::StartOfMonthFilter(), "{value|mm}");

    // Add axis title using 10pts Arial Bold Italic font
    c->yAxis()->setTitle("Power Usage (Watt)", "arialbi.ttf", 10);
    c->yAxis2()->setTitle("Effective Load (kg)", "arialbi.ttf", 10);

    // Add a line layer to the chart using a line width of 2 pixels.
    LineLayer *layer = c->addLineLayer();
    layer->setLineWidth(2);

    // Add 2 data series to the line layer
    layer->setXData(timeStamps);
    layer->addDataSet(data0, 0xcc0000, "Power Usage");
    layer->addDataSet(data1, 0x008800, "Effective Load")->setUseYAxis2();

    // Set the chart image to the QChartViewer
    viewer->setChart(c);
}
示例#7
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;
}
示例#8
0
int main(int argc, char *argv[])
{
    // The data for the line chart
    double data0[] = {60.2, 51.7, 81.3, 48.6, 56.2, 68.9, 52.8};
    double data1[] = {30.0, 32.7, 33.9, 29.5, 32.2, 28.4, 29.8};
    const char *labels[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};

    // Create a XYChart object of size 300 x 180 pixels, with a pale yellow (0xffffc0) background, a
    // black border, and 1 pixel 3D border effect.
    XYChart *c = new XYChart(300, 180, 0xffffc0, 0x000000, 1);

    // Set the plotarea at (45, 35) and of size 240 x 120 pixels, with white background. Turn on
    // both horizontal and vertical grid lines with light grey color (0xc0c0c0)
    c->setPlotArea(45, 35, 240, 120, 0xffffff, -1, -1, 0xc0c0c0, -1);

    // Add a legend box at (45, 12) (top of the chart) using horizontal layout and 8pt Arial font
    // Set the background and border color to Transparent.
    c->addLegend(45, 12, false, "", 8)->setBackground(Chart::Transparent);

    // Add a title to the chart using 9pt Arial Bold/white font. Use a 1 x 2 bitmap pattern as the
    // background.
    int pattern1[] = {0x004000, 0x008000};
    c->addTitle("Server Load (Jun 01 - Jun 07)", "arialbd.ttf", 9, 0xffffff)->setBackground(
        c->patternColor(IntArray(pattern1, (int)(sizeof(pattern1) / sizeof(pattern1[0]))), 2));

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

    // Set the labels on the x axis
    c->xAxis()->setLabels(StringArray(labels, (int)(sizeof(labels) / sizeof(labels[0]))));

    // Add a line layer to the chart
    LineLayer *layer = c->addLineLayer();

    // Add the first line. Plot the points with a 7 pixel square symbol
    layer->addDataSet(DoubleArray(data0, (int)(sizeof(data0) / sizeof(data0[0]))), 0xcf4040, "Peak"
        )->setDataSymbol(Chart::SquareSymbol, 7);

    // Add the second line. Plot the points with a 9 pixel dismond symbol
    layer->addDataSet(DoubleArray(data1, (int)(sizeof(data1) / sizeof(data1[0]))), 0x40cf40,
        "Average")->setDataSymbol(Chart::DiamondSymbol, 9);

    // Enable data label on the data points. Set the label format to nn%.
    layer->setDataLabelFormat("{value|0}%");

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

    //free up resources
    delete c;
    return 0;
}
示例#9
0
文件: overlapbar.cpp 项目: vopl/sp
int main(int argc, char *argv[])
{
    // The data for the bar chart
    double data0[] = {100, 125, 156, 147, 87, 124, 178, 109, 140, 106, 192, 122};
    double data1[] = {122, 156, 179, 211, 198, 177, 160, 220, 190, 188, 220, 270};
    double data2[] = {167, 190, 213, 267, 250, 320, 212, 199, 245, 267, 240, 310};
    const char *labels[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
        "Sept", "Oct", "Nov", "Dec"};

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

    // Add a title to the chart using 14 pts Arial Bold Italic font
    c->addTitle("Product Revenue For Last 3 Years", "arialbi.ttf", 14);

    // Set the plot area at (50, 50) and of size 500 x 200. Use two alternative
    // background colors (f8f8f8 and ffffff)
    c->setPlotArea(50, 50, 500, 200, 0xf8f8f8, 0xffffff);

    // Add a legend box at (50, 25) using horizontal layout. Use 8pts Arial as font,
    // with transparent background.
    c->addLegend(50, 25, false, "arial.ttf", 8)->setBackground(Chart::Transparent);

    // Set the x axis labels
    c->xAxis()->setLabels(StringArray(labels, sizeof(labels)/sizeof(labels[0])));

    // Draw the ticks between label positions (instead of at label positions)
    c->xAxis()->setTickOffset(0.5);

    // Add a multi-bar layer with 3 data sets
    BarLayer *layer = c->addBarLayer(Chart::Side);
    layer->addDataSet(DoubleArray(data0, sizeof(data0)/sizeof(data0[0])), 0xff8080,
        "Year 2003");
    layer->addDataSet(DoubleArray(data1, sizeof(data1)/sizeof(data1[0])), 0x80ff80,
        "Year 2004");
    layer->addDataSet(DoubleArray(data2, sizeof(data2)/sizeof(data2[0])), 0x8080ff,
        "Year 2005");

    // Set 50% overlap between bars
    layer->setOverlapRatio(0.5);

    // Add a title to the y-axis
    c->yAxis()->setTitle("Revenue (USD in millions)");

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

    //free up resources
    delete c;
    return 0;
}
int main(int argc, char *argv[])
{
    // The data for the bar chart
    double data[] = {450, 560, 630, 800, 1100, 1350, 1600, 1950, 2300, 2700};

    // The labels for the bar chart
    const char *labels[] = {"1996", "1997", "1998", "1999", "2000", "2001", "2002",
        "2003", "2004", "2005"};

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

    // Add a title to the chart using 18pts Times Bold Italic font
    c->addTitle("Annual Revenue for Star Tech", "timesbi.ttf", 18);

    // Set the plotarea at (60, 40) and of size 500 x 280 pixels. Use a vertical
    // gradient color from light blue (eeeeff) to deep blue (0000cc) as background.
    // Set border and grid lines to white (ffffff).
    c->setPlotArea(60, 40, 500, 280, c->linearGradientColor(60, 40, 60, 280,
        0xeeeeff, 0x0000cc), -1, 0xffffff, 0xffffff);

    // Add a multi-color bar chart layer using the supplied data. Use soft lighting
    // effect with light direction from left.
    c->addBarLayer(DoubleArray(data, sizeof(data)/sizeof(data[0])), IntArray(0, 0)
        )->setBorderColor(Chart::Transparent, Chart::softLighting(Chart::Left));

    // Set x axis labels using the given labels
    c->xAxis()->setLabels(StringArray(labels, sizeof(labels)/sizeof(labels[0])));

    // Draw the ticks between label positions (instead of at label positions)
    c->xAxis()->setTickOffset(0.5);

    // Add a title to the y axis with 10pts Arial Bold font
    c->yAxis()->setTitle("USD (millions)", "arialbd.ttf", 10);

    // Set axis label style to 8pts Arial Bold
    c->xAxis()->setLabelStyle("arialbd.ttf", 8);
    c->yAxis()->setLabelStyle("arialbd.ttf", 8);

    // Set axis line width to 2 pixels
    c->xAxis()->setWidth(2);
    c->yAxis()->setWidth(2);

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

    //free up resources
    delete c;
    return 0;
}
示例#11
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 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;
}
示例#13
0
文件: multibar.cpp 项目: vopl/sp
int main(int argc, char *argv[])
{
    // The data for the bar chart
    double data0[] = {100, 125, 245, 147, 67};
    double data1[] = {85, 156, 179, 211, 123};
    double data2[] = {97, 87, 56, 267, 157};
    const char *labels[] = {"Mon", "Tue", "Wed", "Thu", "Fri"};

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

    // Add a title to the chart using 10 pt Arial font
    c->addTitle("         Average Weekday Network Load", "", 10);

    // Set the plot area at (50, 25) and of size 320 x 180. Use two alternative
    // background colors (0xffffc0 and 0xffffe0)
    c->setPlotArea(50, 25, 320, 180, 0xffffc0, 0xffffe0);

    // Add a legend box at (55, 18) using horizontal layout. Use 8 pt Arial font,
    // with transparent background
    c->addLegend(55, 18, false, "", 8)->setBackground(Chart::Transparent);

    // Add a title to the y-axis
    c->yAxis()->setTitle("Throughput (MBytes Per Hour)");

    // Reserve 20 pixels at the top of the y-axis for the legend box
    c->yAxis()->setTopMargin(20);

    // Set the x axis labels
    c->xAxis()->setLabels(StringArray(labels, sizeof(labels)/sizeof(labels[0])));

    // Add a multi-bar layer with 3 data sets and 3 pixels 3D depth
    BarLayer *layer = c->addBarLayer(Chart::Side, 3);
    layer->addDataSet(DoubleArray(data0, sizeof(data0)/sizeof(data0[0])), 0xff8080,
        "Server #1");
    layer->addDataSet(DoubleArray(data1, sizeof(data1)/sizeof(data1[0])), 0x80ff80,
        "Server #2");
    layer->addDataSet(DoubleArray(data2, sizeof(data2)/sizeof(data2[0])), 0x8080ff,
        "Server #3");

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

    //free up resources
    delete c;
    return 0;
}
示例#14
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
 	QChartViewer viewer;

	//
	// Draw Chart and set to QChartViewer
	//

	// The data for the bar chart
    double data[] = {85, 156, 179.5, 211, 123};

	// The labels for the bar chart
    const char *labels[] = {"Mon", "Tue", "Wed", "Thu", "Fri"};

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

    // Set the plotarea at (30, 20) and of size 200 x 200 pixels
    c->setPlotArea(30, 20, 200, 200);

    // Add a bar chart layer using the given data
    c->addBarLayer(DoubleArray(data, sizeof(data)/sizeof(data[0])));

    // Set the labels on the x axis.
    c->xAxis()->setLabels(StringArray(labels, sizeof(labels)/sizeof(labels[0])));

    // Output the chart
    viewer.setChart(c);
	
    // Include tool tip for the chart
    viewer.setImageMap(
    	c->getHTMLImageMap("", "", "title='{xLabel}: US${value}K'"));

	// In this sample project, we do not need to chart object any more, so we 
	// delete it now.
    delete c;
    
    //
    // Show the viewer
    //
    
    viewer.show();
    return app.exec();
}
示例#15
0
void GraphWidget::drawFullChart(){
    nameList.clear();

    initChartViewer();

    XYChart *c = new XYChart(size.width(), 100, Chart::Transparent);

    c->setPlotArea(10, 5, c->getWidth() - 65, c->getHeight() - 15, 0x000000, -1, 0xC8C8C8,
        Chart::Transparent, 0xffffff);

    c->xAxis()->setColors(Chart::Transparent);
    c->xAxis()->setLabelStyle("arial.ttf", 10);
    c->xAxis()->setLabelGap(-1);
    c->xAxis()->setLabelAlignment(1);

    c->yAxis()->setColors(Chart::Transparent, Chart::Transparent);

    //遍历查询结果并绘制结果
    int ea_result_count = ea_results.size();
    //设置X轴的label
    for(int i = 0;i < ea_result_count;i++){
        ExchangeRateResult *ea_result = ea_results[i];
        DoubleArray y_data = ea_result->getYData();

        //添加图层
        LineLayer *layer = c->addLineLayer();
        layer->setFastLineMode();
        layer->setLineWidth(1);
        //设置X轴
        layer->setXData(getXData(i));
        //设置Y轴
        layer->addDataSet(y_data, ea_result->getColor(), ea_result->getName().toUtf8().data());
    }

    c->xAxis()->setDateScale(m_ChartViewer->getValueAtViewPort("x", 0), m_ChartViewer->getValueAtViewPort("x", 1));

//    c->xAxis()->setTickDensity(75);

    c->yAxis()->setRounding(false, false);

    delete m_ViewPortControl->getChart();
    m_ViewPortControl->setChart(c);
    drawChart();
}
示例#16
0
int main(int argc, char *argv[])
{
    // The data for the bar chart
    double data[] = {85, 156, 179, 211, 123, 189, 166};

    // The labels for the bar chart
    const char *labels[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};

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

    // Add a title box using grey (0x555555) 24pt Arial Bold font
    c->addTitle("    Bar Chart Demonstration", "arialbd.ttf", 24, 0x555555);

    // Set the plotarea at (70, 60) and of size 500 x 300 pixels, with transparent background and
    // border and light grey (0xcccccc) horizontal grid lines
    c->setPlotArea(70, 60, 500, 300, Chart::Transparent, -1, Chart::Transparent, 0xcccccc);

    // Set the x and y axis stems to transparent and the label font to 12pt Arial
    c->xAxis()->setColors(Chart::Transparent);
    c->yAxis()->setColors(Chart::Transparent);
    c->xAxis()->setLabelStyle("arial.ttf", 12);
    c->yAxis()->setLabelStyle("arial.ttf", 12);

    // Add a blue (0x6699bb) bar chart layer with transparent border using the given data
    c->addBarLayer(DoubleArray(data, (int)(sizeof(data) / sizeof(data[0]))), 0x6699bb
        )->setBorderColor(Chart::Transparent);

    // Set the labels on the x axis.
    c->xAxis()->setLabels(StringArray(labels, (int)(sizeof(labels) / sizeof(labels[0]))));

    // For the automatic y-axis labels, set the minimum spacing to 40 pixels.
    c->yAxis()->setTickDensity(40);

    // Add a title to the y axis using dark grey (0x555555) 14pt Arial Bold font
    c->yAxis()->setTitle("Y-Axis Title Placeholder", "arialbd.ttf", 14, 0x555555);

    // Output the chart
    c->makeChart("simplebar2.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;
}
示例#18
0
int main(int argc, char *argv[])
{
    // The data for the chart
    double dataY[] = {1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1};
    double dataX[] = {Chart::chartTime(2008, 7, 1, 0, 0, 0), Chart::chartTime(2008, 7, 1, 2, 17, 2),
        Chart::chartTime(2008, 7, 1, 8, 5, 30), Chart::chartTime(2008, 7, 1, 10, 54, 10),
        Chart::chartTime(2008, 7, 1, 15, 40, 0), Chart::chartTime(2008, 7, 1, 18, 22, 20),
        Chart::chartTime(2008, 7, 1, 22, 17, 14), Chart::chartTime(2008, 7, 2, 2, 55, 50),
        Chart::chartTime(2008, 7, 2, 8, 17, 14), Chart::chartTime(2008, 7, 2, 11, 55, 50),
        Chart::chartTime(2008, 7, 2, 13, 17, 14), Chart::chartTime(2008, 7, 2, 17, 55, 50),
        Chart::chartTime(2008, 7, 2, 20, 17, 14), Chart::chartTime(2008, 7, 3, 0, 0, 0)};

    // In this example, we only use position 1, 3, 5 for the data series. Positions 0, 2, 4, 6 are
    // empty and serve as gaps.
    const char *labels[] = {"", "ON Only Filling", "",
        "<*font,color=cc2200*>ON<*/font*> / <*font,color=00aa22*>OFF<*/font*> Filling", "",
        "Logic Line", ""};

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

    // Add a title to the chart using 10 points Arial Bold font. Set top/bottom margins to 12
    // pixels.
    TextBox *title = c->addTitle("Binary Data Series Demonstration", "arialbd.ttf", 10);

    // Tentatively set the plotarea at (100, 30) and of size 470 x 120 pixels. Use transparent
    // border. Use grey (888888) solid line and light grey (ccccc) dotted line as major and minor
    // vertical grid lines.
    c->setPlotArea(100, 30, 470, 120, -1, -1, Chart::Transparent)->setGridColor(Chart::Transparent,
        0x888888, Chart::Transparent, c->dashLineColor(0xcccccc, Chart::DotLine));

    // Set axes to transparent
    c->xAxis()->setColors(Chart::Transparent);
    c->yAxis()->setColors(Chart::Transparent);

    // Set the y axis labels
    c->yAxis()->setLabels(StringArray(labels, (int)(sizeof(labels) / sizeof(labels[0]))));

    // Set y-axis label style to 8pt Arial Bold
    c->yAxis()->setLabelStyle("arialbd.ttf", 8);

    // Set x-axis major and minor tick density to 50 and 5 pixels. ChartDirector auto-scaling will
    // use this as the guideline when putting ticks on the x-axis.
    c->xAxis()->setTickDensity(50, 5);

    // Use "<*font=Arial Bold*>{value|mmm dd}" for the first label of an hour, and "{value|hh:nn}"
    // for all other labels.
    c->xAxis()->setMultiFormat(Chart::StartOfDayFilter(), "<*font=arialbd.ttf*>{value|mmm dd}",
        Chart::AllPassFilter(), "{value|hh:nn}");

    //
    // A Logic Line can be achieved using a StepLineLayer in ChartDirector
    //

    // Shift the data by 4.5, so instead of 0 - 1, it is now 4.5 to 5.5, or fluctuate around the y =
    // 5 (Logic Line label) position.
    ArrayMath shiftedLine0 = ArrayMath(DoubleArray(dataY, (int)(sizeof(dataY) / sizeof(dataY[0])))
        ).add(4.5);

    // Add step lines using the original and the reversed data
    StepLineLayer *layer0 = c->addStepLineLayer(shiftedLine0, 0x0000ff);
    layer0->setXData(DoubleArray(dataX, (int)(sizeof(dataX) / sizeof(dataX[0]))));

    //
    // To perform ON/OFF filling, we draw the logic line, and its reverse, and fill the region in
    // between
    //

    // Shift the data by 2.5, so instead of 0 - 1, it is now 2.5 to 3.5, or fluctuate around the y =
    // 3 (ON/OFF Filing label) position.
    ArrayMath shiftedLine1 = ArrayMath(DoubleArray(dataY, (int)(sizeof(dataY) / sizeof(dataY[0])))
        ).add(2.5);
    // Reverse the data, so the 0 becomes 1 and 1 becomes 0, and shift it as well.
    ArrayMath reverseShiftedLine1 = ArrayMath(DoubleArray(dataY, (int)(sizeof(dataY) / sizeof(dataY[
        0])))).mul(-1).add(3.5);

    // Add step lines using the original and the reversed data
    StepLineLayer *layer1 = c->addStepLineLayer(shiftedLine1, Chart::Transparent);
    layer1->addDataSet(reverseShiftedLine1, Chart::Transparent);
    layer1->setXData(DoubleArray(dataX, (int)(sizeof(dataX) / sizeof(dataX[0]))));

    // Fill the region between the two step lines with green (00aa22) or red (cc2200), depending on
    // whether the original or the reserve is higher.
    c->addInterLineLayer(layer1->getLine(0), layer1->getLine(1), 0x00aa22, 0xcc2200);

    //
    // The ON Only filling is the same as ON/OFF filling, except the OFF filling color is
    // transparent
    //

    // Shift the data by 0.5, so instead of 0 - 1, it is now 0.5 to 1.5, or fluctuate around the y =
    // 1 (ON Only Filing label) position.
    ArrayMath shiftedLine2 = ArrayMath(DoubleArray(dataY, (int)(sizeof(dataY) / sizeof(dataY[0])))
        ).add(0.5);
    // Reverse the data, so the 0 becomes 1 and 1 becomes 0, and shift it as well.
    ArrayMath reverseShiftedLine2 = ArrayMath(DoubleArray(dataY, (int)(sizeof(dataY) / sizeof(dataY[
        0])))).mul(-1).add(1.5);

    // Add step lines using the original and the reversed data
    StepLineLayer *layer2 = c->addStepLineLayer(shiftedLine2, Chart::Transparent);
    layer2->addDataSet(reverseShiftedLine2, Chart::Transparent);
    layer2->setXData(DoubleArray(dataX, (int)(sizeof(dataX) / sizeof(dataX[0]))));

    // Fill the region between the two step lines with green (00aa22) or transparent, depending on
    // whether the original or the reserve is higher.
    c->addInterLineLayer(layer2->getLine(0), layer2->getLine(1), 0x00aa22, Chart::Transparent);

    // Adjust the plot area size, such that the bounding box (inclusive of axes) is 10 pixels from
    // the left edge, 10 pixels  below the title, 30 pixels from the right edge, and 10 pixels above
    // the bottom edge.
    c->packPlotArea(10, title->getHeight() + 10, c->getWidth() - 30, c->getHeight() - 10);

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

    //free up resources
    delete c;
    return 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;
}
示例#20
0
//
// Draw the chart and display it in the given viewer
//
void ZoomScrollTrack2::drawChart(QChartViewer *viewer)
{
    // Get the start date and end date that are visible on the chart.
    double viewPortStartDate = viewer->getValueAtViewPort("x", viewer->getViewPortLeft());
    double viewPortEndDate = viewer->getValueAtViewPort("x", viewer->getViewPortLeft() +
        viewer->getViewPortWidth());

    // Get the array indexes that corresponds to the visible start and end dates
    int startIndex = (int)floor(Chart::bSearch(m_timeStamps, viewPortStartDate));
    int endIndex = (int)ceil(Chart::bSearch(m_timeStamps, viewPortEndDate));
    int noOfPoints = endIndex - startIndex + 1;

    // Extract the part of the data array that are visible.
    DoubleArray viewPortTimeStamps = DoubleArray(m_timeStamps.data + startIndex, noOfPoints);
    DoubleArray viewPortDataSeriesA = DoubleArray(m_dataSeriesA.data + startIndex, noOfPoints);
    DoubleArray viewPortDataSeriesB = DoubleArray(m_dataSeriesB.data + startIndex, noOfPoints);
    DoubleArray viewPortDataSeriesC = DoubleArray(m_dataSeriesC.data + startIndex, noOfPoints);

    //
    // At this stage, we have extracted the visible data. We can use those data to plot the chart.
    //

    ///////////////////////////////////////////////////////////////////////////////////////
    // Configure overall chart appearance.
    ///////////////////////////////////////////////////////////////////////////////////////

    // Create an XYChart object of size 650 x 350 pixels, with a white (ffffff) background and grey
    // (aaaaaa) border
    XYChart *c = new XYChart(650, 350, 0xffffff, 0xaaaaaa);

    // Set the plotarea at (55, 55) with width 90 pixels less than chart width, and height 90 pixels
    // less than chart height. Use a vertical gradient from light blue (f0f6ff) to sky blue (a0c0ff)
    // as background. Set border to transparent and grid lines to white (ffffff).
    c->setPlotArea(55, 55, c->getWidth() - 90, c->getHeight() - 90, c->linearGradientColor(0, 55, 0,
        c->getHeight() - 35, 0xf0f6ff, 0xa0c0ff), -1, Chart::Transparent, 0xffffff, 0xffffff);

    // As the data can lie outside the plotarea in a zoomed chart, we need enable clipping.
    c->setClipping();

    // Add a title to the chart using 18 pts Times New Roman Bold Italic font
    c->addTitle("   Zooming and Scrolling with Track Line (2)", "timesbi.ttf", 18);

    // Add a legend box at (55, 30) using horizontal layout. Use 8pts Arial Bold as font. Set the
    // background and border color to Transparent and use line style legend key.
    LegendBox *b = c->addLegend(55, 30, false, "arialbd.ttf", 8);
    b->setBackground(Chart::Transparent);
    b->setLineStyleKey();

    // Set the axis stem to transparent
    c->xAxis()->setColors(Chart::Transparent);
    c->yAxis()->setColors(Chart::Transparent);

    // Add axis title using 10pts Arial Bold Italic font
    c->yAxis()->setTitle("Ionic Temperature (C)", "arialbi.ttf", 10);

    ///////////////////////////////////////////////////////////////////////////////////////
    // Add data to chart
    ///////////////////////////////////////////////////////////////////////////////////////

    //
    // In this example, we represent the data by lines. You may modify the code below to use other
    // representations (areas, scatter plot, etc).
    //

    // Add a line layer for the lines, using a line width of 2 pixels
    LineLayer *layer = c->addLineLayer();
    layer->setLineWidth(2);

    // In this demo, we do not have too many data points. In real code, the chart may contain a lot
    // of data points when fully zoomed out - much more than the number of horizontal pixels in this
    // plot area. So it is a good idea to use fast line mode.
    layer->setFastLineMode();

    // Now we add the 3 data series to a line layer, using the color red (ff0000), green
    // (00cc00) and blue (0000ff)
    layer->setXData(viewPortTimeStamps);
    layer->addDataSet(viewPortDataSeriesA, 0xff3333, "Alpha");
    layer->addDataSet(viewPortDataSeriesB, 0x008800, "Beta");
    layer->addDataSet(viewPortDataSeriesC, 0x3333CC, "Gamma");

    ///////////////////////////////////////////////////////////////////////////////////////
    // Configure axis scale and labelling
    ///////////////////////////////////////////////////////////////////////////////////////

    // Set the x-axis as a date/time axis with the scale according to the view port x range.
    viewer->syncDateAxisWithViewPort("x", c->xAxis());

    //
    // In this demo, the time range can be from a few years to a few days. We demonstrate how to set
    // up different date/time format based on the time range.
    //

    // If all ticks are yearly aligned, then we use "yyyy" as the label format.
    c->xAxis()->setFormatCondition("align", 360 * 86400);
    c->xAxis()->setLabelFormat("{value|yyyy}");

    // If all ticks are monthly aligned, then we use "mmm yyyy" in bold font as the first
    // label of a year, and "mmm" for other labels.
    c->xAxis()->setFormatCondition("align", 30 * 86400);
    c->xAxis()->setMultiFormat(Chart::StartOfYearFilter(), "<*font=bold*>{value|mmm yyyy}",
        Chart::AllPassFilter(), "{value|mmm}");

    // If all ticks are daily algined, then we use "mmm dd<*br*>yyyy" in bold font as the
    // first label of a year, and "mmm dd" in bold font as the first label of a month, and
    // "dd" for other labels.
    c->xAxis()->setFormatCondition("align", 86400);
    c->xAxis()->setMultiFormat(Chart::StartOfYearFilter(),
        "<*block,halign=left*><*font=bold*>{value|mmm dd<*br*>yyyy}",
        Chart::StartOfMonthFilter(), "<*font=bold*>{value|mmm dd}");
    c->xAxis()->setMultiFormat(Chart::AllPassFilter(), "{value|dd}");

    // For all other cases (sub-daily ticks), use "hh:nn<*br*>mmm dd" for the first label of
    // a day, and "hh:nn" for other labels.
    c->xAxis()->setFormatCondition("else");
    c->xAxis()->setMultiFormat(Chart::StartOfDayFilter(),
        "<*font=bold*>{value|hh:nn<*br*>mmm dd}", Chart::AllPassFilter(), "{value|hh:nn}");

    ///////////////////////////////////////////////////////////////////////////////////////
    // Output the chart
    ///////////////////////////////////////////////////////////////////////////////////////

    // We need to update the track line too. If the mouse is moving on the chart (eg. if 
    // the user drags the mouse on the chart to scroll it), the track line will be updated
    // in the MouseMovePlotArea event. Otherwise, we need to update the track line here.
	if ((!viewer->isInMouseMoveEvent()) && viewer->isMouseOnPlotArea())
        trackLineLabel(c, viewer->getPlotAreaMouseX());

    delete viewer->getChart();
    viewer->setChart(c);
}
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;
}
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;
}
示例#23
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[] = {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;
}
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;
}
示例#25
0
文件: layergantt.cpp 项目: vopl/sp
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;
}
示例#26
0
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;
}
int main(int argc, char *argv[])
{
    // The data for the chart
    double data[] = {40, 15, 7, 5, 2};

    // The labels for the chart
    const char *labels[] = {"Hard Disk", "PCB", "Printer", "CDROM", "Keyboard"};

    // In the pareto chart, the line data are just the accumulation of the raw data,
    // scaled to a range of 0 - 100%
    ArrayMath lineData = ArrayMath(DoubleArray(data, sizeof(data)/sizeof(data[0])));
    lineData.acc();
    double scaleFactor = lineData.max() / 100;
    if (scaleFactor == 0) {
        // Avoid division by zero error for zero data
        scaleFactor = 1;
    }
    lineData.div(scaleFactor);

    // Create a XYChart object of size 480 x 300 pixels. Set background color to
    // brushed silver, with a grey (bbbbbb) border and 2 pixel 3D raised effect. Use
    // rounded corners. Enable soft drop shadow.
    XYChart *c = new XYChart(400, 300, Chart::brushedSilverColor(), 0xbbbbbb, 2);
    c->setRoundedFrame();
    c->setDropShadow();

    // Add a title to the chart using 15 points Arial Italic. Set top/bottom margins
    // to 12 pixels.
    TextBox *title = c->addTitle("Pareto Chart Demonstration", "ariali.ttf", 15);
    title->setMargin(0, 0, 12, 12);

    // Tentatively set the plotarea at (50, 40). Set the width to 100 pixels less
    // than the chart width, and the height to 80 pixels less than the chart height.
    // Use pale grey (f4f4f4) background, transparent border, and dark grey (444444)
    // dotted grid lines.
    c->setPlotArea(50, 40, c->getWidth() - 100, c->getHeight() - 80, 0xf4f4f4, -1,
                   Chart::Transparent, c->dashLineColor(0x444444, Chart::DotLine));

    // Add a line layer for the pareto line
    LineLayer *lineLayer = c->addLineLayer();

    // Add the pareto line using deep blue (0000ff) as the color, with circle symbols
    lineLayer->addDataSet(lineData.result(), 0x0000ff)->setDataSymbol(
        Chart::CircleShape, 9, 0x0000ff, 0x0000ff);

    // Set the line width to 2 pixel
    lineLayer->setLineWidth(2);

    // Bind the line layer to the secondary (right) y-axis.
    lineLayer->setUseYAxis2();

    // Add a multi-color bar layer using the given data.
    BarLayer *barLayer = c->addBarLayer(DoubleArray(data,
                                        sizeof(data)/sizeof(data[0])), IntArray(0, 0));

    // Set soft lighting for the bars with light direction from the right
    barLayer->setBorderColor(Chart::Transparent, Chart::softLighting(Chart::Right));

    // Set the labels on the x axis.
    c->xAxis()->setLabels(StringArray(labels, sizeof(labels)/sizeof(labels[0])));

    // Set the secondary (right) y-axis scale as 0 - 100 with a tick every 20 units
    c->yAxis2()->setLinearScale(0, 100, 20);

    // Set the format of the secondary (right) y-axis label to include a percentage
    // sign
    c->yAxis2()->setLabelFormat("{value}%");

    // Set the relationship between the two y-axes, which only differ by a scaling
    // factor
    c->yAxis()->syncAxis(c->yAxis2(), scaleFactor);

    // Set the format of the primary y-axis label foramt to show no decimal point
    c->yAxis()->setLabelFormat("{value|0}");

    // Add a title to the primary y-axis
    c->yAxis()->setTitle("Frequency");

    // Set all axes to transparent
    c->xAxis()->setColors(Chart::Transparent);
    c->yAxis()->setColors(Chart::Transparent);
    c->yAxis2()->setColors(Chart::Transparent);

    // Adjust the plot area size, such that the bounding box (inclusive of axes) is
    // 10 pixels from the left edge, just below the title, 10 pixels from the right
    // edge, and 20 pixels from the bottom edge.
    c->packPlotArea(10, title->getHeight(), c->getWidth() - 10, c->getHeight() - 20);

    // Output the chart
    c->makeChart("pareto.jpg");

    //free up resources
    delete c;
    return 0;
}
示例#28
0
int main(int argc, char *argv[])
{
    // The x and y coordinates of the grid
    double dataX[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    double dataY[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

    // Use random numbers for the z values on the XY grid
    RanSeries *r = new RanSeries(999);
    DoubleArray dataZ = r->get2DSeries((int)(sizeof(dataX) / sizeof(dataX[0])), (int)(sizeof(dataY)
         / sizeof(dataY[0])), -0.9, 1.15);

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

    // Set the plotarea at (30, 25) and of size 400 x 400 pixels. Use semi-transparent grey
    // (0xdd000000) horizontal and vertical grid lines
    c->setPlotArea(50, 25, 400, 400, -1, -1, Chart::Transparent, 0xdd000000, -1);

    // Set the x and y axis stems to transparent and the label font to 12pt Arial
    c->xAxis()->setColors(Chart::Transparent);
    c->yAxis()->setColors(Chart::Transparent);
    c->xAxis()->setLabelStyle("arial.ttf", 12);
    c->yAxis()->setLabelStyle("arial.ttf", 12);

    // Set the x-axis and y-axis scale
    c->xAxis()->setLinearScale(0, 10, 1);
    c->yAxis()->setLinearScale(0, 10, 1);

    // Add a contour layer using the given data
    ContourLayer *layer = c->addContourLayer(DoubleArray(dataX, (int)(sizeof(dataX) / sizeof(dataX[0
        ]))), DoubleArray(dataY, (int)(sizeof(dataY) / sizeof(dataY[0]))), dataZ);

    // Move the grid lines in front of the contour layer
    c->getPlotArea()->moveGridBefore(layer);

    // Define the color scale
    double colorScale[] = {-0.8, 0x0066ff, -0.5, 0x66ccff, -0.3, 0x66ffff, 0, 0x88ff88, 0.4,
        0x00ff00, 0.7, 0xffff00, 0.9, 0xff6600, 1.0, 0xcc0000, 1.1};
    // Apply the color scale, and specify the underflow and overflow colors for regions exceeding
    // the color scale
    layer->colorAxis()->setColorScale(DoubleArray(colorScale, (int)(sizeof(colorScale) / sizeof(
        colorScale[0]))), 0x0000cc, 0x000000);

    //
    // Instead of displaying the color axis, we use a legend box to display the colors. This is
    // useful for colors that are unevenly spaced on the color axis.
    //

    // Add a legend box at (460, 25) with vertical layout, with 12pt Arial font, transparent
    // background and border, icon size of 15 x 15 pixels, and line spacing of 8 pixels.
    LegendBox *b = c->addLegend(460, 25, true, "arial.ttf", 12);
    b->setBackground(Chart::Transparent, Chart::Transparent);
    b->setKeySize(15, 15);
    b->setKeySpacing(0, 8);

    // Add the legend box entries
    b->addKey("> 1.1 (Critical)", 0x000000);
    b->addKey("1.0 to 1.1 (Alert)", 0xcc0000);
    b->addKey("0.9 to 1.0", 0xff6600);
    b->addKey("0.7 to 0.9", 0xffff00);
    b->addKey("0.4 to 0.7", 0x00ff00);
    b->addKey("0.0 to 0.4", 0x88ff88);
    b->addKey("-0.3 to 0.0", 0x66ffff);
    b->addKey("-0.5 to -0.3", 0x66ccff);
    b->addKey("-0.8 to -0.5", 0x0066ff);
    b->addKey("< -0.8", 0x0000cc);

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

    //free up resources
    delete r;
    delete c;
    return 0;
}
示例#29
0
int main(int argc, char *argv[])
{
    // The data for the bar chart
    double data0[] = {100, 115, 165, 107, 67};
    double data1[] = {85, 106, 129, 161, 123};
    double data2[] = {67, 87, 86, 167, 157};

    // The labels for the bar chart
    const char *labels[] = {"Mon", "Tue", "Wed", "Thu", "Fri"};

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

    // Set the plotarea at (70, 20) and of size 400 x 300 pixels, with transparent background and
    // border and light grey (0xcccccc) horizontal grid lines
    c->setPlotArea(70, 20, 400, 300, Chart::Transparent, -1, Chart::Transparent, 0xcccccc);

    // Add a legend box at (480, 20) using vertical layout and 12pt Arial font. Set background and
    // border to transparent and key icon border to the same as the fill color.
    LegendBox *b = c->addLegend(480, 20, true, "arial.ttf", 12);
    b->setBackground(Chart::Transparent, Chart::Transparent);
    b->setKeyBorder(Chart::SameAsMainColor);

    // Set the x and y axis stems to transparent and the label font to 12pt Arial
    c->xAxis()->setColors(Chart::Transparent);
    c->yAxis()->setColors(Chart::Transparent);
    c->xAxis()->setLabelStyle("arial.ttf", 12);
    c->yAxis()->setLabelStyle("arial.ttf", 12);

    // Add a stacked bar layer
    BarLayer *layer = c->addBarLayer(Chart::Stack);

    // Add the three data sets to the bar layer
    layer->addDataSet(DoubleArray(data0, (int)(sizeof(data0) / sizeof(data0[0]))), 0xaaccee,
        "Server # 1");
    layer->addDataSet(DoubleArray(data1, (int)(sizeof(data1) / sizeof(data1[0]))), 0xbbdd88,
        "Server # 2");
    layer->addDataSet(DoubleArray(data2, (int)(sizeof(data2) / sizeof(data2[0]))), 0xeeaa66,
        "Server # 3");

    // Set the bar border to transparent
    layer->setBorderColor(Chart::Transparent);

    // Enable labelling for the entire bar and use 12pt Arial font
    layer->setAggregateLabelStyle("arial.ttf", 12);

    // Enable labelling for the bar segments and use 12pt Arial font with center alignment
    layer->setDataLabelStyle("arial.ttf", 10)->setAlignment(Chart::Center);

    // For a vertical stacked bar with positive data, the first data set is at the bottom. For the
    // legend box, by default, the first entry at the top. We can reverse the legend order to make
    // the legend box consistent with the stacked bar.
    layer->setLegendOrder(Chart::ReverseLegend);

    // Set the labels on the x axis.
    c->xAxis()->setLabels(StringArray(labels, (int)(sizeof(labels) / sizeof(labels[0]))));

    // For the automatic y-axis labels, set the minimum spacing to 40 pixels.
    c->yAxis()->setTickDensity(40);

    // Add a title to the y axis using dark grey (0x555555) 14pt Arial Bold font
    c->yAxis()->setTitle("Y-Axis Title Placeholder", "arialbd.ttf", 14, 0x555555);

    // Output the chart
    c->makeChart("stackedbar.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;
}