##// 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 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include <QApplication>
22 22 #include <QMainWindow>
23 23 #include <QChartView>
24 24 #include <QBarSeries>
25 25 #include <QBarSet>
26 26 #include <QLegend>
27 27
28 28 QTCOMMERCIALCHART_USE_NAMESPACE
29 29
30 30 int main(int argc, char *argv[])
31 31 {
32 32 QApplication a(argc, argv);
33 33
34 34 //![1]
35 35 QBarCategories categories;
36 36 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
37 37 //![1]
38 38
39 39 //![2]
40 40 QBarSet *set0 = new QBarSet("Jane");
41 41 QBarSet *set1 = new QBarSet("John");
42 42 QBarSet *set2 = new QBarSet("Axel");
43 43 QBarSet *set3 = new QBarSet("Mary");
44 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);
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);
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);
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);
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);
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.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.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.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.4, 5) << QPointF(1.8, 6) << QPointF(2.6, 7) << QPointF(3.8, 8) << QPointF(4.8, 9) << QPointF(5.8, 10);
51 51 //![2]
52 52
53 53 //![3]
54 54 QBarSeries* series = new QBarSeries();
55 55 series->setCategories(categories);
56 56 series->appendBarSet(set0);
57 57 series->appendBarSet(set1);
58 58 series->appendBarSet(set2);
59 59 series->appendBarSet(set3);
60 60 series->appendBarSet(set4);
61 61
62 62 //![3]
63 63
64 64 //![4]
65 65 QChart* chart = new QChart();
66 66 chart->addSeries(series);
67 67 chart->setTitle("Simple barchart example");
68 68 //![4]
69 69
70 70 //![5]
71 71 chart->legend()->setVisible(true);
72 72 chart->legend()->setAlignment(QLegend::AlignmentBottom);
73 73 chart->axisY()->setNiceNumbersEnabled(true);
74 74 //![5]
75 75
76 76 //![6]
77 77 QChartView* chartView = new QChartView(chart);
78 78 chartView->setRenderHint(QPainter::Antialiasing);
79 79 //![6]
80 80
81 81 //![7]
82 82 QMainWindow window;
83 83 window.setCentralWidget(chartView);
84 84 window.resize(400, 300);
85 85 window.show();
86 86 //![7]
87 87
88 88 return a.exec();
89 89 }
General Comments 0
You need to be logged in to leave comments. Login now