##// END OF EJS Templates
updated barchart example to show the possibility to use x values as bar positions
sauimone -
r1174:651df6ba5460
parent child
Show More
@@ -1,89 +1,89
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include <QApplication>
21 #include <QApplication>
22 #include <QMainWindow>
22 #include <QMainWindow>
23 #include <QChartView>
23 #include <QChartView>
24 #include <QBarSeries>
24 #include <QBarSeries>
25 #include <QBarSet>
25 #include <QBarSet>
26 #include <QLegend>
26 #include <QLegend>
27
27
28 QTCOMMERCIALCHART_USE_NAMESPACE
28 QTCOMMERCIALCHART_USE_NAMESPACE
29
29
30 int main(int argc, char *argv[])
30 int main(int argc, char *argv[])
31 {
31 {
32 QApplication a(argc, argv);
32 QApplication a(argc, argv);
33
33
34 //![1]
34 //![1]
35 QBarCategories categories;
35 QBarCategories categories;
36 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
36 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
37 //![1]
37 //![1]
38
38
39 //![2]
39 //![2]
40 QBarSet *set0 = new QBarSet("Jane");
40 QBarSet *set0 = new QBarSet("Jane");
41 QBarSet *set1 = new QBarSet("John");
41 QBarSet *set1 = new QBarSet("John");
42 QBarSet *set2 = new QBarSet("Axel");
42 QBarSet *set2 = new QBarSet("Axel");
43 QBarSet *set3 = new QBarSet("Mary");
43 QBarSet *set3 = new QBarSet("Mary");
44 QBarSet *set4 = new QBarSet("Samantha");
44 QBarSet *set4 = new QBarSet("Samantha");
45
45
46 *set0 << QPointF(0.0, 1) << QPointF(1.0, 2) << QPointF(2.0, 3) << QPointF(3.0, 4) << QPointF(4.0, 5) << QPointF(5.0, 6);
46 *set0 << QPointF(0.0, 1) << QPointF(1.0, 2) << QPointF(2.4, 3) << QPointF(3.0, 4) << QPointF(4.0, 5) << QPointF(5.0, 6);
47 *set1 << QPointF(0.2, 2) << QPointF(1.2, 3) << QPointF(2.2, 4) << QPointF(3.2, 5) << QPointF(4.2, 6) << QPointF(5.2, 7);
47 *set1 << QPointF(0.1, 2) << QPointF(1.2, 3) << QPointF(2.45, 4) << QPointF(3.2, 5) << QPointF(4.2, 6) << QPointF(5.2, 7);
48 *set2 << QPointF(0.4, 3) << QPointF(1.4, 4) << QPointF(2.4, 5) << QPointF(3.4, 6) << QPointF(4.4, 7) << QPointF(5.4, 8);
48 *set2 << QPointF(0.2, 3) << QPointF(1.4, 4) << QPointF(2.50, 5) << QPointF(3.4, 6) << QPointF(4.4, 7) << QPointF(5.4, 8);
49 *set3 << QPointF(0.6, 4) << QPointF(1.6, 5) << QPointF(2.6, 6) << QPointF(3.6, 7) << QPointF(4.6, 8) << QPointF(5.6, 9);
49 *set3 << QPointF(0.3, 4) << QPointF(1.6, 5) << QPointF(2.55, 6) << QPointF(3.6, 7) << QPointF(4.6, 8) << QPointF(5.6, 9);
50 *set4 << QPointF(0.8, 5) << QPointF(1.8, 6) << QPointF(2.8, 7) << QPointF(3.8, 8) << QPointF(4.8, 9) << QPointF(5.8, 10);
50 *set4 << QPointF(0.4, 5) << QPointF(1.8, 6) << QPointF(2.6, 7) << QPointF(3.8, 8) << QPointF(4.8, 9) << QPointF(5.8, 10);
51 //![2]
51 //![2]
52
52
53 //![3]
53 //![3]
54 QBarSeries* series = new QBarSeries();
54 QBarSeries* series = new QBarSeries();
55 series->setCategories(categories);
55 series->setCategories(categories);
56 series->appendBarSet(set0);
56 series->appendBarSet(set0);
57 series->appendBarSet(set1);
57 series->appendBarSet(set1);
58 series->appendBarSet(set2);
58 series->appendBarSet(set2);
59 series->appendBarSet(set3);
59 series->appendBarSet(set3);
60 series->appendBarSet(set4);
60 series->appendBarSet(set4);
61
61
62 //![3]
62 //![3]
63
63
64 //![4]
64 //![4]
65 QChart* chart = new QChart();
65 QChart* chart = new QChart();
66 chart->addSeries(series);
66 chart->addSeries(series);
67 chart->setTitle("Simple barchart example");
67 chart->setTitle("Simple barchart example");
68 //![4]
68 //![4]
69
69
70 //![5]
70 //![5]
71 chart->legend()->setVisible(true);
71 chart->legend()->setVisible(true);
72 chart->legend()->setAlignment(QLegend::AlignmentBottom);
72 chart->legend()->setAlignment(QLegend::AlignmentBottom);
73 chart->axisY()->setNiceNumbersEnabled(true);
73 chart->axisY()->setNiceNumbersEnabled(true);
74 //![5]
74 //![5]
75
75
76 //![6]
76 //![6]
77 QChartView* chartView = new QChartView(chart);
77 QChartView* chartView = new QChartView(chart);
78 chartView->setRenderHint(QPainter::Antialiasing);
78 chartView->setRenderHint(QPainter::Antialiasing);
79 //![6]
79 //![6]
80
80
81 //![7]
81 //![7]
82 QMainWindow window;
82 QMainWindow window;
83 window.setCentralWidget(chartView);
83 window.setCentralWidget(chartView);
84 window.resize(400, 300);
84 window.resize(400, 300);
85 window.show();
85 window.show();
86 //![7]
86 //![7]
87
87
88 return a.exec();
88 return a.exec();
89 }
89 }
General Comments 0
You need to be logged in to leave comments. Login now