@@ -1,104 +1,105 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 <QBoxPlotSeries> |
|
25 | 25 | #include <QBoxSet> |
|
26 | 26 | #include <QLegend> |
|
27 | 27 | #include <QBarCategoryAxis> |
|
28 | #include <QFile> | |
|
28 | 29 | |
|
29 | 30 | #include "boxdatareader.h" |
|
30 | 31 | |
|
31 | 32 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
32 | 33 | |
|
33 | 34 | int main(int argc, char *argv[]) |
|
34 | 35 | { |
|
35 | 36 | QApplication a(argc, argv); |
|
36 | 37 | |
|
37 | 38 | //! [1] |
|
38 | 39 | QBoxPlotSeries *acmeSeries = new QBoxPlotSeries(); |
|
39 | 40 | acmeSeries->setName("Acme Ltd"); |
|
40 | 41 | |
|
41 | 42 | QBoxPlotSeries *boxWhiskSeries = new QBoxPlotSeries(); |
|
42 | 43 | boxWhiskSeries->setName("BoxWhisk Inc"); |
|
43 | 44 | //! [1] |
|
44 | 45 | |
|
45 | 46 | //! [2] |
|
46 | 47 | QFile acmeData(":acme"); |
|
47 | 48 | if (!acmeData.open(QIODevice::ReadOnly | QIODevice::Text)) |
|
48 | 49 | return 1; |
|
49 | 50 | |
|
50 | 51 | BoxDataReader dataReader(&acmeData); |
|
51 | 52 | while (!dataReader.atEnd()) { |
|
52 | 53 | QBoxSet *set = dataReader.readBox(); |
|
53 | 54 | if (set) |
|
54 | 55 | acmeSeries->append(set); |
|
55 | 56 | } |
|
56 | 57 | //! [2] |
|
57 | 58 | |
|
58 | 59 | //! [3] |
|
59 | 60 | QFile boxwhiskData(":boxwhisk"); |
|
60 | 61 | if (!boxwhiskData.open(QIODevice::ReadOnly | QIODevice::Text)) |
|
61 | 62 | return 1; |
|
62 | 63 | |
|
63 | 64 | dataReader.readFile(&boxwhiskData); |
|
64 | 65 | while (!dataReader.atEnd()) { |
|
65 | 66 | QBoxSet *set = dataReader.readBox(); |
|
66 | 67 | if (set) |
|
67 | 68 | boxWhiskSeries->append(set); |
|
68 | 69 | } |
|
69 | 70 | //! [3] |
|
70 | 71 | |
|
71 | 72 | //! [4] |
|
72 | 73 | QChart *chart = new QChart(); |
|
73 | 74 | chart->addSeries(acmeSeries); |
|
74 | 75 | chart->addSeries(boxWhiskSeries); |
|
75 | 76 | chart->setTitle("Acme Ltd and BoxWhisk Inc share deviation in 2012"); |
|
76 | 77 | chart->setAnimationOptions(QChart::SeriesAnimations); |
|
77 | 78 | //! [4] |
|
78 | 79 | |
|
79 | 80 | //! [5] |
|
80 | 81 | chart->createDefaultAxes(); |
|
81 | 82 | chart->axisY()->setMin(15.0); |
|
82 | 83 | chart->axisY()->setMax(34.0); |
|
83 | 84 | //! [5] |
|
84 | 85 | |
|
85 | 86 | //! [6] |
|
86 | 87 | chart->legend()->setVisible(true); |
|
87 | 88 | chart->legend()->setAlignment(Qt::AlignBottom); |
|
88 | 89 | //! [6] |
|
89 | 90 | |
|
90 | 91 | //! [7] |
|
91 | 92 | QChartView *chartView = new QChartView(chart); |
|
92 | 93 | chartView->setRenderHint(QPainter::Antialiasing); |
|
93 | 94 | //! [7] |
|
94 | 95 | |
|
95 | 96 | //! [8] |
|
96 | 97 | QMainWindow window; |
|
97 | 98 | window.setCentralWidget(chartView); |
|
98 | 99 | window.resize(800, 600); |
|
99 | 100 | window.show(); |
|
100 | 101 | //! [8] |
|
101 | 102 | |
|
102 | 103 | return a.exec(); |
|
103 | 104 | } |
|
104 | 105 |
General Comments 0
You need to be logged in to leave comments.
Login now