qtcharts/example/stackedbarchart/main.cpp

54 lines
1.7 KiB
C++
Raw Normal View History

2012-01-27 13:27:43 +00:00
#include <QApplication>
#include <QMainWindow>
2012-02-22 12:21:08 +00:00
#include <qchartview.h>
2012-02-20 12:10:45 +00:00
#include <qstackedbarchartseries.h>
2012-02-13 15:09:19 +00:00
#include <qbarset.h>
#include <qbarcategory.h>
2012-01-27 13:27:43 +00:00
2012-02-22 12:21:08 +00:00
#include "custombarset.h"
2012-01-27 13:27:43 +00:00
QTCOMMERCIALCHART_USE_NAMESPACE
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMainWindow window;
QBarCategory *category = new QBarCategory;
*category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
2012-02-13 15:09:19 +00:00
2012-02-22 12:21:08 +00:00
QStackedBarChartSeries* series = new QStackedBarChartSeries(category);
2012-02-13 15:09:19 +00:00
2012-02-22 12:21:08 +00:00
// We use custom set, which connects some signals. Could use QBarSet here if we don't need signals
CustomBarSet *set0 = new CustomBarSet("Bub");
CustomBarSet *set1 = new CustomBarSet("Bob");
CustomBarSet *set2 = new CustomBarSet("Guybrush");
CustomBarSet *set3 = new CustomBarSet("Larry");
CustomBarSet *set4 = new CustomBarSet("Zak");
2012-01-27 13:27:43 +00:00
// Create some test data to chart
*set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12;
2012-02-22 12:21:08 +00:00
*set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2;
*set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5;
*set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7;
*set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6;
2012-02-22 12:21:08 +00:00
series->addBarSet(set0);
series->addBarSet(set1);
series->addBarSet(set2);
series->addBarSet(set3);
series->addBarSet(set4);
2012-02-22 12:21:08 +00:00
QChartView* chartView = new QChartView(&window);
chartView->addSeries(series);
chartView->setChartTitle("simple stacked barchart");
chartView->setChartTheme(QChart::ChartThemeIcy);
2012-01-27 13:27:43 +00:00
2012-02-22 12:21:08 +00:00
window.setCentralWidget(chartView);
2012-01-27 13:27:43 +00:00
window.resize(400, 300);
window.show();
return a.exec();
}