##// END OF EJS Templates
updated barchart examples
sauimone -
r170:ff886517a70e
parent child
Show More
@@ -1,47 +1,49
1 #include <QApplication>
1 #include <QApplication>
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <QStandardItemModel>
3 #include <QStandardItemModel>
4 #include <percentbarchartseries.h>
4 #include <percentbarchartseries.h>
5 #include "chartwidget.h"
5 #include "chartwidget.h"
6 #include <qbarcategory.h>
7 #include <qbarset.h>
6
8
7 QTCOMMERCIALCHART_USE_NAMESPACE
9 QTCOMMERCIALCHART_USE_NAMESPACE
8
10
9 int main(int argc, char *argv[])
11 int main(int argc, char *argv[])
10 {
12 {
11 QApplication a(argc, argv);
13 QApplication a(argc, argv);
12 QMainWindow window;
14 QMainWindow window;
13
15
14 PercentBarChartSeries* series0 = new PercentBarChartSeries();
16 QBarCategory category;
17 category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Nov" << "Dec";
18
19 PercentBarChartSeries* series0 = new PercentBarChartSeries(category);
20
21 QBarSet barSet0;
22 QBarSet barSet1;
23 QBarSet barSet2;
24 QBarSet barSet3;
25 QBarSet barSet4;
15
26
16 // Create some test data to chart
27 // Create some test data to chart
17 QList<qreal> data0;
28 barSet0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10;
18 data0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10;
29 barSet1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0;
19 QList<qreal> data1;
30 barSet2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1;
20 data1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0;
31 barSet3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5;
21 QList<qreal> data2;
32 barSet4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10;
22 data2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1;
33
23 QList<qreal> data3;
34 series0->addBarSet(barSet0);
24 data3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5;
35 series0->addBarSet(barSet1);
25 QList<qreal> data4;
36 series0->addBarSet(barSet2);
26 data4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10;
37 series0->addBarSet(barSet3);
27
38 series0->addBarSet(barSet4);
28 series0->addData(data0);
29 series0->addData(data1);
30 series0->addData(data2);
31 series0->addData(data3);
32 series0->addData(data4);
33
34 QList<QString> labels;
35 labels << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Nov" << "Dec";
36 series0->setLabels(labels);
37
39
38 ChartWidget* chartWidget = new ChartWidget(&window);
40 ChartWidget* chartWidget = new ChartWidget(&window);
39 chartWidget->addSeries(series0);
41 chartWidget->addSeries(series0);
40
42
41 window.setCentralWidget(chartWidget);
43 window.setCentralWidget(chartWidget);
42 window.resize(400, 300);
44 window.resize(400, 300);
43 window.show();
45 window.show();
44
46
45 return a.exec();
47 return a.exec();
46 }
48 }
47
49
@@ -1,47 +1,49
1 #include <QApplication>
1 #include <QApplication>
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <QStandardItemModel>
3 #include <QStandardItemModel>
4 #include <stackedbarchartseries.h>
4 #include <stackedbarchartseries.h>
5 #include "chartwidget.h"
5 #include "chartwidget.h"
6 #include <qbarset.h>
7 #include <qbarcategory.h>
6
8
7 QTCOMMERCIALCHART_USE_NAMESPACE
9 QTCOMMERCIALCHART_USE_NAMESPACE
8
10
9 int main(int argc, char *argv[])
11 int main(int argc, char *argv[])
10 {
12 {
11 QApplication a(argc, argv);
13 QApplication a(argc, argv);
12 QMainWindow window;
14 QMainWindow window;
13
15
14 StackedBarChartSeries* series0 = new StackedBarChartSeries();
16 QBarCategory category;
17 category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Nov" << "Dec";
18
19 StackedBarChartSeries* series0 = new StackedBarChartSeries(category);
20
21 QBarSet barSet0;
22 QBarSet barSet1;
23 QBarSet barSet2;
24 QBarSet barSet3;
25 QBarSet barSet4;
15
26
16 // Create some test data to chart
27 // Create some test data to chart
17 QList<qreal> data0;
28 barSet0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10;
18 data0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10;
29 barSet1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0;
19 QList<qreal> data1;
30 barSet2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1;
20 data1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0;
31 barSet3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5;
21 QList<qreal> data2;
32 barSet4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10;
22 data2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1;
33
23 QList<qreal> data3;
34 series0->addBarSet(barSet0);
24 data3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5;
35 series0->addBarSet(barSet1);
25 QList<qreal> data4;
36 series0->addBarSet(barSet2);
26 data4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10;
37 series0->addBarSet(barSet3);
27
38 series0->addBarSet(barSet4);
28 series0->addData(data0);
29 series0->addData(data1);
30 series0->addData(data2);
31 series0->addData(data3);
32 series0->addData(data4);
33
34 QList<QString> labels;
35 labels << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Nov" << "Dec";
36 series0->setLabels(labels);
37
39
38 ChartWidget* chartWidget = new ChartWidget(&window);
40 ChartWidget* chartWidget = new ChartWidget(&window);
39 chartWidget->addSeries(series0);
41 chartWidget->addSeries(series0);
40
42
41 window.setCentralWidget(chartWidget);
43 window.setCentralWidget(chartWidget);
42 window.resize(400, 300);
44 window.resize(400, 300);
43 window.show();
45 window.show();
44
46
45 return a.exec();
47 return a.exec();
46 }
48 }
47
49
General Comments 0
You need to be logged in to leave comments. Login now