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