@@ -1,119 +1,122 | |||||
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 <QLineSeries> |
|
24 | #include <QLineSeries> | |
25 | #include <QValuesAxis> |
|
25 | #include <QValuesAxis> | |
26 | #include <QBarCategoriesAxis> |
|
26 | #include <QBarCategoriesAxis> | |
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 | QLineSeries* series = new QLineSeries(); |
|
35 | QLineSeries* series = new QLineSeries(); | |
36 |
*series << QPointF(0, 6) << QPointF(0.5, 4) << QPointF(1, |
|
36 | *series << QPointF(0, 0.6) << QPointF(0.5, 0.4) << QPointF(1, 2) << QPointF(1.5, 1.2) << QPointF(2, 1.0); | |
37 | QChart* chart = new QChart(); |
|
37 | QChart* chart = new QChart(); | |
38 | chart->legend()->hide(); |
|
38 | chart->legend()->hide(); | |
39 | chart->addSeries(series); |
|
39 | chart->addSeries(series); | |
40 | //![1] |
|
40 | //![1] | |
41 |
|
41 | |||
42 | //![2] |
|
42 | //![2] | |
43 | // Customize series |
|
43 | // Customize series | |
44 | QPen pen(QRgb(0xfdb157)); |
|
44 | QPen pen(QRgb(0xfdb157)); | |
45 | pen.setWidth(5); |
|
45 | pen.setWidth(5); | |
46 | series->setPen(pen); |
|
46 | series->setPen(pen); | |
47 |
|
47 | |||
48 | // Customize chart title |
|
48 | // Customize chart title | |
49 | QFont font; |
|
49 | QFont font; | |
50 | font.setPixelSize(18); |
|
50 | font.setPixelSize(18); | |
51 | chart->setTitleFont(font); |
|
51 | chart->setTitleFont(font); | |
52 | chart->setTitleBrush(QBrush(Qt::white)); |
|
52 | chart->setTitleBrush(QBrush(Qt::white)); | |
53 | chart->setTitle("Customchart example"); |
|
53 | chart->setTitle("Customchart example"); | |
54 |
|
54 | |||
55 | // Customize chart background |
|
55 | // Customize chart background | |
56 | QLinearGradient backgroundGradient; |
|
56 | QLinearGradient backgroundGradient; | |
57 | backgroundGradient.setStart(QPointF(0,0)); |
|
57 | backgroundGradient.setStart(QPointF(0,0)); | |
58 | backgroundGradient.setFinalStop(QPointF(0,1)); |
|
58 | backgroundGradient.setFinalStop(QPointF(0,1)); | |
59 | backgroundGradient.setColorAt(0.0, QRgb(0xd2d0d1)); |
|
59 | backgroundGradient.setColorAt(0.0, QRgb(0xd2d0d1)); | |
60 | backgroundGradient.setColorAt(1.0, QRgb(0x4c4547)); |
|
60 | backgroundGradient.setColorAt(1.0, QRgb(0x4c4547)); | |
61 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
61 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
62 | chart->setBackgroundBrush(backgroundGradient); |
|
62 | chart->setBackgroundBrush(backgroundGradient); | |
63 | //![2] |
|
63 | //![2] | |
64 |
|
64 | |||
65 | //![3] |
|
65 | //![3] | |
66 | QBarCategoriesAxis* axisX = new QBarCategoriesAxis; |
|
66 | QBarCategoriesAxis* axisX = new QBarCategoriesAxis; | |
67 |
Q |
|
67 | QBarCategoriesAxis* axisY = new QBarCategoriesAxis; | |
68 |
|
68 | |||
69 | // Customize axis label font |
|
69 | // Customize axis label font | |
70 | QFont labelsFont; |
|
70 | QFont labelsFont; | |
71 | labelsFont.setPixelSize(12); |
|
71 | labelsFont.setPixelSize(12); | |
72 | axisX->setLabelsFont(labelsFont); |
|
72 | axisX->setLabelsFont(labelsFont); | |
73 | axisY->setLabelsFont(labelsFont); |
|
73 | axisY->setLabelsFont(labelsFont); | |
74 |
|
74 | |||
75 | // Customize axis colors |
|
75 | // Customize axis colors | |
76 | QPen axisPen(QRgb(0xd18952)); |
|
76 | QPen axisPen(QRgb(0xd18952)); | |
77 | axisPen.setWidth(2); |
|
77 | axisPen.setWidth(2); | |
78 | axisX->setAxisPen(axisPen); |
|
78 | axisX->setAxisPen(axisPen); | |
79 | axisY->setAxisPen(axisPen); |
|
79 | axisY->setAxisPen(axisPen); | |
80 |
|
80 | |||
81 | // Customize axis label colors |
|
81 | // Customize axis label colors | |
82 | QBrush axisBrush(Qt::white); |
|
82 | QBrush axisBrush(Qt::white); | |
83 | axisX->setLabelsBrush(axisBrush); |
|
83 | axisX->setLabelsBrush(axisBrush); | |
84 | axisY->setLabelsBrush(axisBrush); |
|
84 | axisY->setLabelsBrush(axisBrush); | |
85 |
|
85 | |||
86 | // Customize grid lines and shades |
|
86 | // Customize grid lines and shades | |
87 | axisX->setGridLineVisible(false); |
|
87 | axisX->setGridLineVisible(false); | |
88 | axisY->setGridLineVisible(false); |
|
88 | axisY->setGridLineVisible(false); | |
89 | axisY->setShadesPen(Qt::NoPen); |
|
89 | axisY->setShadesPen(Qt::NoPen); | |
90 | axisY->setShadesBrush(QBrush(QRgb(0xa5a2a3))); |
|
90 | axisY->setShadesBrush(QBrush(QRgb(0xa5a2a3))); | |
91 | axisY->setShadesVisible(true); |
|
91 | axisY->setShadesVisible(true); | |
92 | //![3] |
|
92 | //![3] | |
93 |
|
93 | |||
94 | //![4] |
|
94 | //![4] | |
95 | axisX->append("low"); |
|
95 | axisX->append("low"); | |
96 | axisX->append("optimal"); |
|
96 | axisX->append("optimal"); | |
97 | axisX->append("high"); |
|
97 | axisX->append("high"); | |
98 |
|
|
98 | ||
99 |
|
|
99 | axisX->setRange("low","high"); | |
100 | axisY->setRange(0,10); |
|
100 | axisY->append("slow"); | |
101 | axisY->setTicksCount(4); |
|
101 | axisY->append("medium"); | |
|
102 | axisY->append("fast"); | |||
|
103 | axisY->setRange("slow","fast"); | |||
|
104 | // axisY->setTicksCount(4); | |||
102 | chart->setAxisX(axisX, series); |
|
105 | chart->setAxisX(axisX, series); | |
103 | chart->setAxisY(axisY, series); |
|
106 | chart->setAxisY(axisY, series); | |
104 | //![4] |
|
107 | //![4] | |
105 |
|
108 | |||
106 | //![5] |
|
109 | //![5] | |
107 | QChartView* chartView = new QChartView(chart); |
|
110 | QChartView* chartView = new QChartView(chart); | |
108 | chartView->setRenderHint(QPainter::Antialiasing); |
|
111 | chartView->setRenderHint(QPainter::Antialiasing); | |
109 | //![5] |
|
112 | //![5] | |
110 |
|
113 | |||
111 | //![6] |
|
114 | //![6] | |
112 | QMainWindow window; |
|
115 | QMainWindow window; | |
113 | window.setCentralWidget(chartView); |
|
116 | window.setCentralWidget(chartView); | |
114 | window.resize(400, 300); |
|
117 | window.resize(400, 300); | |
115 | window.show(); |
|
118 | window.show(); | |
116 | //![6] |
|
119 | //![6] | |
117 |
|
120 | |||
118 | return a.exec(); |
|
121 | return a.exec(); | |
119 | } |
|
122 | } |
General Comments 0
You need to be logged in to leave comments.
Login now