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;
}
//
// Draw chart
//
void RealtimeChart::drawChart()
{
    // Create an XYChart object 600 x 270 pixels in size, with light white (ffffff)
    // background, white (000000) border, no raised effect, and with a rounded frame.
    XYChart *c = new XYChart(645, 270, 0xffffff, 0xffffff, 0);
    QColor bgColor = palette().color(backgroundRole()).rgb();
    //c->setRoundedFrame((bgColor.red() << 16) + (bgColor.green() << 8) + bgColor.blue());

    // Set the plotarea at (55, 62) and of size 520 x 175 pixels. Use white (ffffff)
    // background. Enable both horizontal and vertical grids by setting their colors to
    // grey (cccccc). Set clipping mode to clip the data lines to the plot area.
    c->setPlotArea(55, 62, 580, 185, 0xffffff, -1, -1, 0xcccccc, 0xcccccc);
    c->setClipping();

    // Add a title to the chart using 15 pts Times New Roman Bold Italic font, with a light
    // grey (dddddd) background, black (000000) border, and a glass like raised effect.
    c->addTitle(m_mainTitle, "arialbd.ttf", 15);

    // Add a legend box at the top of the plot area with 9pts Arial Bold font. We set the
    // legend box to the same width as the plot area and use grid layout (as opposed to
    // flow or top/down layout). This distributes the 3 legend icons evenly on top of the
    // plot area.
    LegendBox *b = c->addLegend2(55, 33, 3, "arialbd.ttf", 9);
    b->setBackground(Chart::Transparent, Chart::Transparent);
    b->setWidth(580);

    // Configure the y-axis with a 10pts Arial Bold axis title
    c->yAxis()->setTitle(m_yTitle, "arialbd.ttf", 10);

    // Configure the x-axis to auto-scale with at least 75 pixels between major tick and
    // 15  pixels between minor ticks. This shows more minor grid lines on the chart.
    c->xAxis()->setTickDensity(75, 15);

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

    // Now we add the data to the chart.
    double lastTime = m_timeStamps[sampleSize - 1];
    if (lastTime != Chart::NoValue)
    {
        // Set up the x-axis to show the time range in the data buffer
        c->xAxis()->setDateScale(lastTime - DataInterval * sampleSize / 1000, lastTime);

        // Set the x-axis label format
        c->xAxis()->setLabelFormat("{value|hh:nn:ss}");

        // Create a line layer to plot the lines
        LineLayer *layer = c->addLineLayer();

        // The x-coordinates are the timeStamps.
        layer->setXData(DoubleArray(m_timeStamps, sampleSize));

        // The 3 data series are used to draw 3 lines. Here we put the latest data values
        // as part of the data set name, so you can see them updated in the legend box.
        char buffer[1024];

        sprintf(buffer, "%s: <*bgColor=FFCCCC*> %.2f ", m_labelA, m_dataSeriesA[sampleSize - 1]);
        layer->addDataSet(DoubleArray(m_dataSeriesA, sampleSize), 0xff0000, buffer);

        sprintf(buffer, "%s: <*bgColor=CCFFCC*> %.2f ", m_labelB, m_dataSeriesB[sampleSize - 1]);
        layer->addDataSet(DoubleArray(m_dataSeriesB, sampleSize), 0x00cc00, buffer);
    }

    // Set the chart image to the WinChartViewer
    m_ChartViewer->setChart(c);
    delete c;
}