@@ -1,181 +1,183 | |||
|
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 | import QtQuick 1.0 |
|
22 | 22 | import QtCommercial.Chart 1.1 |
|
23 | 23 | import QmlCustomModel 1.0 |
|
24 | 24 | |
|
25 | 25 | Rectangle { |
|
26 | 26 | anchors.fill: parent |
|
27 | 27 | |
|
28 | 28 | //![1] |
|
29 | 29 | ChartView { |
|
30 | 30 | id: chartView |
|
31 | 31 | title: "Top-5 car brand shares in Finland" |
|
32 | 32 | anchors.fill: parent |
|
33 | 33 | animationOptions: ChartView.SeriesAnimations |
|
34 | 34 | |
|
35 | 35 | BarCategoriesAxis { |
|
36 | 36 | id: categoriesAxis |
|
37 | 37 | categories: ["2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014" ] |
|
38 | 38 | min: "2007" |
|
39 | 39 | max: "2014" |
|
40 | title: "Year" | |
|
40 | 41 | } |
|
41 | 42 | |
|
42 | 43 | ValueAxis { |
|
43 | 44 | id: valueAxis |
|
44 | 45 | min: 0 |
|
45 | 46 | max: 60 |
|
47 | title: "Sales count [ku]" | |
|
46 | 48 | } |
|
47 | 49 | // ... |
|
48 | 50 | //![1] |
|
49 | 51 | |
|
50 | 52 | //![2] |
|
51 | 53 | CustomModel { |
|
52 | 54 | id: customModel |
|
53 | 55 | verticalHeaders: ["Manufacturer", "Volkswagen", "Toyota", "Ford", "Skoda", "Volvo", "Others"] |
|
54 | 56 | CustomModelElement { values: [0, "Manufacturer", 0, 1, 2, 3, 4] } |
|
55 | 57 | CustomModelElement { values: [1, "Volkswagen", 10.3, 12.0, 12.8, 13.0, 13.8] } |
|
56 | 58 | CustomModelElement { values: [2, "Toyota", 13.8, 13.5, 16.2, 13.7, 10.7] } |
|
57 | 59 | CustomModelElement { values: [3, "Ford", 6.4, 7.1, 8.9, 8.2, 8.6] } |
|
58 | 60 | CustomModelElement { values: [4, "Skoda", 4.7, 5.8, 6.9, 8.3, 8.2] } |
|
59 | 61 | CustomModelElement { values: [5, "Volvo", 7.1, 6.7, 6.5, 6.3, 7.0] } |
|
60 | 62 | CustomModelElement { values: [6, "Others", 57.7, 54.9, 48.7, 50.5, 51.7] } |
|
61 | 63 | } |
|
62 | 64 | //![2] |
|
63 | 65 | |
|
64 | 66 | //![5] |
|
65 | 67 | BarSeries { |
|
66 | 68 | id: myBarSeries |
|
67 | 69 | name: "Others" |
|
68 | 70 | axisX: categoriesAxis |
|
69 | 71 | axisY: valueAxis |
|
70 | 72 | barWidth: 0.9 |
|
71 | 73 | visible: false |
|
72 | 74 | HBarModelMapper { |
|
73 | 75 | model: customModel |
|
74 | 76 | firstBarSetRow: 6 |
|
75 | 77 | lastBarSetRow: 6 |
|
76 | 78 | firstColumn: 2 |
|
77 | 79 | } |
|
78 | 80 | } |
|
79 | 81 | //![5] |
|
80 | 82 | |
|
81 | 83 | //![4] |
|
82 | 84 | LineSeries { |
|
83 | 85 | id: lineSeries1 |
|
84 | 86 | name: "Volkswagen" |
|
85 | 87 | axisX: categoriesAxis |
|
86 | 88 | axisY: valueAxis |
|
87 | 89 | visible: false |
|
88 | 90 | HXYModelMapper { |
|
89 | 91 | model: customModel |
|
90 | 92 | xRow: 0 |
|
91 | 93 | yRow: 1 |
|
92 | 94 | firstColumn: 2 |
|
93 | 95 | } |
|
94 | 96 | } |
|
95 | 97 | //![4] |
|
96 | 98 | |
|
97 | 99 | LineSeries { |
|
98 | 100 | id: lineSeries2 |
|
99 | 101 | name: "Toyota" |
|
100 | 102 | axisX: categoriesAxis |
|
101 | 103 | axisY: valueAxis |
|
102 | 104 | visible: false |
|
103 | 105 | HXYModelMapper { |
|
104 | 106 | model: customModel |
|
105 | 107 | xRow: 0 |
|
106 | 108 | yRow: 2 |
|
107 | 109 | firstColumn: 2 |
|
108 | 110 | } |
|
109 | 111 | } |
|
110 | 112 | |
|
111 | 113 | LineSeries { |
|
112 | 114 | id: lineSeries3 |
|
113 | 115 | name: "Ford" |
|
114 | 116 | axisX: categoriesAxis |
|
115 | 117 | axisY: valueAxis |
|
116 | 118 | visible: false |
|
117 | 119 | HXYModelMapper { |
|
118 | 120 | model: customModel |
|
119 | 121 | xRow: 0 |
|
120 | 122 | yRow: 3 |
|
121 | 123 | firstColumn: 2 |
|
122 | 124 | } |
|
123 | 125 | } |
|
124 | 126 | |
|
125 | 127 | LineSeries { |
|
126 | 128 | id: lineSeries4 |
|
127 | 129 | name: "Skoda" |
|
128 | 130 | axisX: categoriesAxis |
|
129 | 131 | axisY: valueAxis |
|
130 | 132 | visible: false |
|
131 | 133 | HXYModelMapper { |
|
132 | 134 | model: customModel |
|
133 | 135 | xRow: 0 |
|
134 | 136 | yRow: 4 |
|
135 | 137 | firstColumn: 2 |
|
136 | 138 | } |
|
137 | 139 | } |
|
138 | 140 | |
|
139 | 141 | LineSeries { |
|
140 | 142 | id: lineSeries5 |
|
141 | 143 | name: "Volvo" |
|
142 | 144 | axisX: categoriesAxis |
|
143 | 145 | axisY: valueAxis |
|
144 | 146 | visible: false |
|
145 | 147 | HXYModelMapper { |
|
146 | 148 | model: customModel |
|
147 | 149 | xRow: 0 |
|
148 | 150 | yRow: 5 |
|
149 | 151 | firstColumn: 2 |
|
150 | 152 | } |
|
151 | 153 | } |
|
152 | 154 | |
|
153 | 155 | //![3] |
|
154 | 156 | PieSeries { |
|
155 | 157 | id: pieSeries |
|
156 | 158 | size: 0.4 |
|
157 | 159 | horizontalPosition: 0.85 |
|
158 | 160 | verticalPosition: 0.4 |
|
159 | 161 | onClicked: { |
|
160 | 162 | // Show the selection by exploding the slice |
|
161 | 163 | slice.exploded = !slice.exploded; |
|
162 | 164 | |
|
163 | 165 | // Update the line series to show the yearly data for this slice |
|
164 | 166 | for (var i = 0; i < chartView.count; i++) { |
|
165 | 167 | if (chartView.series(i).name == slice.label) { |
|
166 | 168 | chartView.series(i).visible = slice.exploded; |
|
167 | 169 | } |
|
168 | 170 | } |
|
169 | 171 | } |
|
170 | 172 | |
|
171 | 173 | } |
|
172 | 174 | VPieModelMapper { |
|
173 | 175 | model: customModel |
|
174 | 176 | series: pieSeries |
|
175 | 177 | labelsColumn: 1 |
|
176 | 178 | valuesColumn: 2 |
|
177 | 179 | firstRow: 1 |
|
178 | 180 | } |
|
179 | 181 | //![3] |
|
180 | 182 | } |
|
181 | 183 | } |
@@ -1,159 +1,162 | |||
|
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 | #ifndef QABSTRACTAXIS_H |
|
22 | 22 | #define QABSTRACTAXIS_H |
|
23 | 23 | |
|
24 | 24 | #include <qchartglobal.h> |
|
25 | 25 | #include <QPen> |
|
26 | 26 | #include <QFont> |
|
27 | 27 | #include <QVariant> |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | class QAbstractAxisPrivate; |
|
32 | 32 | |
|
33 | 33 | class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject |
|
34 | 34 | { |
|
35 | 35 | Q_OBJECT |
|
36 | 36 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) |
|
37 | 37 | Q_PROPERTY(bool lineVisible READ isLineVisible WRITE setLineVisible NOTIFY lineVisibleChanged) |
|
38 | 38 | Q_PROPERTY(QColor color READ linePenColor WRITE setLinePenColor NOTIFY colorChanged) |
|
39 | 39 | Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) |
|
40 | 40 | Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle) |
|
41 | 41 | Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont) |
|
42 | 42 | Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged) |
|
43 | 43 | Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged) |
|
44 | 44 | Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged) |
|
45 | 45 | Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged) |
|
46 | 46 | Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged) |
|
47 | Q_PROPERTY(bool titleVisible READ titleVisible WRITE setTitleVisible) | |
|
48 | Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont) | |
|
49 | Q_PROPERTY(QString title READ title WRITE setTitle) | |
|
47 | 50 | |
|
48 | 51 | public: |
|
49 | 52 | |
|
50 | 53 | enum AxisType { |
|
51 | 54 | AxisTypeNoAxis = 0x0, |
|
52 | 55 | AxisTypeValue = 0x1, |
|
53 | 56 | AxisTypeBarCategory = 0x2, |
|
54 | 57 | AxisTypeCategory = 0x3, |
|
55 | 58 | AxisTypeDateTime = 0x4 |
|
56 | 59 | }; |
|
57 | 60 | |
|
58 | 61 | Q_DECLARE_FLAGS(AxisTypes, AxisType) |
|
59 | 62 | |
|
60 | 63 | protected: |
|
61 | 64 | explicit QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent = 0); |
|
62 | 65 | |
|
63 | 66 | public: |
|
64 | 67 | ~QAbstractAxis(); |
|
65 | 68 | |
|
66 | 69 | virtual AxisType type() const = 0; |
|
67 | 70 | |
|
68 | 71 | //visibilty handling |
|
69 | 72 | bool isVisible() const; |
|
70 | 73 | void setVisible(bool visible = true); |
|
71 | 74 | |
|
72 | 75 | |
|
73 | 76 | //axis handling |
|
74 | 77 | bool isLineVisible() const; |
|
75 | 78 | void setLineVisible(bool visible = true); |
|
76 | 79 | void setLinePen(const QPen &pen); |
|
77 | 80 | QPen linePen() const; |
|
78 | 81 | void setLinePenColor(QColor color); |
|
79 | 82 | QColor linePenColor() const; |
|
80 | 83 | |
|
81 | 84 | //grid handling |
|
82 | 85 | bool isGridLineVisible() const; |
|
83 | 86 | void setGridLineVisible(bool visible = true); |
|
84 | 87 | void setGridLinePen(const QPen &pen); |
|
85 | 88 | QPen gridLinePen() const; |
|
86 | 89 | |
|
87 | 90 | //labels handling |
|
88 | 91 | bool labelsVisible() const; |
|
89 | 92 | void setLabelsVisible(bool visible = true); |
|
90 | 93 | void setLabelsPen(const QPen &pen); |
|
91 | 94 | QPen labelsPen() const; |
|
92 | 95 | void setLabelsBrush(const QBrush &brush); |
|
93 | 96 | QBrush labelsBrush() const; |
|
94 | 97 | void setLabelsFont(const QFont &font); |
|
95 | 98 | QFont labelsFont() const; |
|
96 | 99 | void setLabelsAngle(int angle); |
|
97 | 100 | int labelsAngle() const; |
|
98 | 101 | void setLabelsColor(QColor color); |
|
99 | 102 | QColor labelsColor() const; |
|
100 | 103 | |
|
101 | 104 | //title handling |
|
102 | 105 | bool titleVisible() const; |
|
103 | 106 | void setTitleVisible(bool visible = true); |
|
104 | 107 | void setTitlePen(const QPen &pen); |
|
105 | 108 | QPen titlePen() const; |
|
106 | 109 | void setTitleBrush(const QBrush &brush); |
|
107 | 110 | QBrush titleBrush() const; |
|
108 | 111 | void setTitleFont(const QFont &font); |
|
109 | 112 | QFont titleFont() const; |
|
110 | 113 | void setTitle(const QString &title); |
|
111 | 114 | QString title() const; |
|
112 | 115 | |
|
113 | 116 | |
|
114 | 117 | //shades handling |
|
115 | 118 | bool shadesVisible() const; |
|
116 | 119 | void setShadesVisible(bool visible = true); |
|
117 | 120 | void setShadesPen(const QPen &pen); |
|
118 | 121 | QPen shadesPen() const; |
|
119 | 122 | void setShadesBrush(const QBrush &brush); |
|
120 | 123 | QBrush shadesBrush() const; |
|
121 | 124 | void setShadesColor(QColor color); |
|
122 | 125 | QColor shadesColor() const; |
|
123 | 126 | void setShadesBorderColor(QColor color); |
|
124 | 127 | QColor shadesBorderColor() const; |
|
125 | 128 | |
|
126 | 129 | Qt::Orientation orientation() const; |
|
127 | 130 | Qt::Alignment alignment() const; |
|
128 | 131 | void setAlignment(Qt::Alignment alignment); |
|
129 | 132 | |
|
130 | 133 | //range handling |
|
131 | 134 | void setMin(const QVariant &min); |
|
132 | 135 | void setMax(const QVariant &max); |
|
133 | 136 | void setRange(const QVariant &min, const QVariant &max); |
|
134 | 137 | |
|
135 | 138 | void show(); |
|
136 | 139 | void hide(); |
|
137 | 140 | |
|
138 | 141 | Q_SIGNALS: |
|
139 | 142 | void visibleChanged(bool visible); |
|
140 | 143 | void lineVisibleChanged(bool visible); |
|
141 | 144 | void labelsVisibleChanged(bool visible); |
|
142 | 145 | void gridVisibleChanged(bool visible); |
|
143 | 146 | void colorChanged(QColor color); |
|
144 | 147 | void labelsColorChanged(QColor color); |
|
145 | 148 | void shadesVisibleChanged(bool visible); |
|
146 | 149 | void shadesColorChanged(QColor color); |
|
147 | 150 | void shadesBorderColorChanged(QColor color); |
|
148 | 151 | |
|
149 | 152 | protected: |
|
150 | 153 | QScopedPointer<QAbstractAxisPrivate> d_ptr; |
|
151 | 154 | Q_DISABLE_COPY(QAbstractAxis) |
|
152 | 155 | friend class ChartDataSet; |
|
153 | 156 | friend class ChartAxis; |
|
154 | 157 | friend class ChartPresenter; |
|
155 | 158 | }; |
|
156 | 159 | |
|
157 | 160 | QTCOMMERCIALCHART_END_NAMESPACE |
|
158 | 161 | |
|
159 | 162 | #endif // QABSTRACTAXIS_H |
General Comments 0
You need to be logged in to leave comments.
Login now