@@ -37,28 +37,44 Rectangle { | |||||
37 | legend.alignment: Qt.AlignTop |
|
37 | legend.alignment: Qt.AlignTop | |
38 |
|
38 | |||
39 | //![2] |
|
39 | //![2] | |
|
40 | BarCategoriesAxis { | |||
|
41 | id: myBarCategoryAxis | |||
|
42 | categories: ["Mo", "Tu", "We", "Th", "Fr"] | |||
|
43 | } | |||
|
44 | ||||
40 |
|
|
45 | BarSeries { | |
41 |
|
|
46 | id: myBarSeries | |
42 | id: categoriesAxis |
|
|||
43 | categories: ["Mo", "Tu", "We", "Th", "Fr", "Sa" ] |
|
|||
44 | } |
|
|||
45 |
|
||||
46 | BarSet { |
|
47 | BarSet { | |
47 | id: rainfallSet |
|
48 | id: rainfallSet | |
48 | label: "Rainfall" |
|
49 | label: "Rainfall" | |
49 | } |
|
50 | } | |
50 | } |
|
51 | } | |
|
52 | ||||
|
53 | ValuesAxis{ | |||
|
54 | id: myValuesAxisY | |||
|
55 | min: 0 | |||
|
56 | max: 10 | |||
|
57 | } | |||
51 |
|
58 | |||
52 |
|
|
59 | LineSeries { | |
53 | id: maxTempSeries |
|
60 | id: maxTempSeries | |
54 | name: "Max. temperature" |
|
61 | name: "Max. temperature" | |
55 | } |
|
62 | } | |
56 |
|
63 | |||
57 |
|
|
64 | LineSeries { | |
58 | id: minTempSeries |
|
65 | id: minTempSeries | |
59 | name: "Min. temperature" |
|
66 | name: "Min. temperature" | |
60 | } |
|
67 | } | |
61 | //![2] |
|
68 | //![2] | |
|
69 | ||||
|
70 | Component.onCompleted: { | |||
|
71 | setAxisX(myBarCategoryAxis,myBarSeries) | |||
|
72 | setAxisX(myBarCategoryAxis,maxTempSeries) | |||
|
73 | setAxisX(myBarCategoryAxis,minTempSeries) | |||
|
74 | setAxisY(myValuesAxisY,maxTempSeries) | |||
|
75 | setAxisY(myValuesAxisY,minTempSeries) | |||
|
76 | setAxisY(myValuesAxisY,myBarSeries) | |||
|
77 | } | |||
62 |
|
|
78 | } | |
63 |
|
79 | |||
64 | // A timer to refresh the forecast every 5 minutes |
|
80 | // A timer to refresh the forecast every 5 minutes | |
@@ -128,10 +144,6 Rectangle { | |||||
128 |
|
144 | |||
129 | function parseWeatherData(weatherData) { |
|
145 | function parseWeatherData(weatherData) { | |
130 | // Clear previous values |
|
146 | // Clear previous values | |
131 | chartView.axisX.min = 0; |
|
|||
132 | chartView.axisX.max = 5; |
|
|||
133 | chartView.axisY.min = 0; |
|
|||
134 | chartView.axisY.max = 5; |
|
|||
135 | maxTempSeries.clear(); |
|
147 | maxTempSeries.clear(); | |
136 | minTempSeries.clear(); |
|
148 | minTempSeries.clear(); | |
137 | weatherImageModel.clear(); |
|
149 | weatherImageModel.clear(); | |
@@ -147,23 +159,23 Rectangle { | |||||
147 | maxTempSeries.append(i, weatherObj.tempMaxC); |
|
159 | maxTempSeries.append(i, weatherObj.tempMaxC); | |
148 | minTempSeries.append(i, weatherObj.tempMinC); |
|
160 | minTempSeries.append(i, weatherObj.tempMinC); | |
149 | rainfallSet.append(i, weatherObj.precipMM); |
|
161 | rainfallSet.append(i, weatherObj.precipMM); | |
150 |
|
||||
151 | weatherImageModel.append({"imageSource":weatherObj.weatherIconUrl[0].value}); |
|
162 | weatherImageModel.append({"imageSource":weatherObj.weatherIconUrl[0].value}); | |
152 | //![5] |
|
163 | //![5] | |
153 |
|
164 | |||
154 | // Update scale of the chart |
|
165 | // Update scale of the chart | |
155 | chartView.axisX.min = 0; |
|
166 | chartView.axisY().max = Math.max(chartView.axisY().max,weatherObj.tempMaxC) | |
156 | chartView.axisX.max = i; |
|
167 | chartView.axisY().max = Math.max(chartView.axisY().max,weatherObj.tempMinC) | |
157 |
|
|
168 | chartView.axisX().min = 0; | |
158 |
|
|
169 | chartView.axisX().max = i+1; | |
159 | while (chartView.axisY.max <= Number(weatherObj.tempMaxC)) |
|
|||
160 | chartView.axisY.max = chartView.axisY.max + 10; |
|
|||
161 |
|
170 | |||
162 | // Set the x-axis labels to the dates of the forecast |
|
171 | // Set the x-axis labels to the dates of the forecast | |
163 |
var xLabels = |
|
172 | var xLabels = myBarCategoryAxis.categories; | |
164 |
xLabels[Number(i) |
|
173 | xLabels[Number(i)] = weatherObj.date.substring(5, 10); | |
165 | xLabels[(Number(i) * 2) + 1] = weatherObj.date.substring(5, 10); |
|
174 | myBarCategoryAxis.categories = xLabels; | |
166 |
|
|
175 | myBarCategoryAxis.visible = true; | |
167 | } |
|
176 | } | |
|
177 | ||||
|
178 | ||||
168 | } |
|
179 | } | |
|
180 | ||||
169 | } |
|
181 | } |
@@ -38,8 +38,6 class DeclarativeChart : public QDeclarativeItem | |||||
38 | Q_PROPERTY(QString title READ title WRITE setTitle) |
|
38 | Q_PROPERTY(QString title READ title WRITE setTitle) | |
39 | Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont) |
|
39 | Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont) | |
40 | Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged) |
|
40 | Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged) | |
41 | Q_PROPERTY(QAbstractAxis *axisX READ axisX) |
|
|||
42 | Q_PROPERTY(QAbstractAxis *axisY READ axisY) |
|
|||
43 | Q_PROPERTY(QLegend *legend READ legend) |
|
41 | Q_PROPERTY(QLegend *legend READ legend) | |
44 | Q_PROPERTY(int count READ count) |
|
42 | Q_PROPERTY(int count READ count) | |
45 | Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) |
|
43 | Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) | |
@@ -114,8 +112,7 public: | |||||
114 | qreal leftMargin(); |
|
112 | qreal leftMargin(); | |
115 | qreal rightMargin(); |
|
113 | qreal rightMargin(); | |
116 |
|
114 | |||
117 | QAbstractAxis *axisX(QAbstractSeries *series = 0); |
|
115 | ||
118 | QAbstractAxis *axisY(QAbstractSeries *series = 0); |
|
|||
119 |
|
116 | |||
120 | public: |
|
117 | public: | |
121 | Q_INVOKABLE QAbstractSeries *series(int index); |
|
118 | Q_INVOKABLE QAbstractSeries *series(int index); | |
@@ -124,6 +121,8 public: | |||||
124 | Q_INVOKABLE void setAxisX(QAbstractAxis* axis, QAbstractSeries *series = 0); |
|
121 | Q_INVOKABLE void setAxisX(QAbstractAxis* axis, QAbstractSeries *series = 0); | |
125 | Q_INVOKABLE void setAxisY(QAbstractAxis* axis, QAbstractSeries *series = 0); |
|
122 | Q_INVOKABLE void setAxisY(QAbstractAxis* axis, QAbstractSeries *series = 0); | |
126 | Q_INVOKABLE void createDefaultAxes(); |
|
123 | Q_INVOKABLE void createDefaultAxes(); | |
|
124 | Q_INVOKABLE QAbstractAxis *axisX(QAbstractSeries *series = 0); | |||
|
125 | Q_INVOKABLE QAbstractAxis *axisY(QAbstractSeries *series = 0); | |||
127 |
|
126 | |||
128 | Q_INVOKABLE void zoom(qreal factor); |
|
127 | Q_INVOKABLE void zoom(qreal factor); | |
129 | Q_INVOKABLE void scrollLeft(qreal pixels); |
|
128 | Q_INVOKABLE void scrollLeft(qreal pixels); |
@@ -95,7 +95,7 protected: | |||||
95 | void createCategoryLabels(QStringList &labels,qreal min, qreal max,const QStringList &categories) const; |
|
95 | void createCategoryLabels(QStringList &labels,qreal min, qreal max,const QStringList &categories) const; | |
96 |
|
96 | |||
97 | public Q_SLOTS: |
|
97 | public Q_SLOTS: | |
98 | void handleAxisUpdated(); |
|
98 | virtual void handleAxisUpdated(); | |
99 | void handleAxisCategoriesUpdated(); |
|
99 | void handleAxisCategoriesUpdated(); | |
100 | void handleRangeChanged(qreal min , qreal max,int tickCount); |
|
100 | void handleRangeChanged(qreal min , qreal max,int tickCount); | |
101 | void handleGeometryChanged(const QRectF &size); |
|
101 | void handleGeometryChanged(const QRectF &size); |
@@ -106,4 +106,14 void ChartCategoriesAxisX::updateGeometry() | |||||
106 | } |
|
106 | } | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
|
109 | void ChartCategoriesAxisX::handleAxisUpdated() | |||
|
110 | { | |||
|
111 | if(m_categoriesAxis->categories()!=m_categories) | |||
|
112 | { | |||
|
113 | m_categories=m_categoriesAxis->categories(); | |||
|
114 | if(ChartAxis::layout().count()==m_categories.size()+1) updateGeometry(); | |||
|
115 | } | |||
|
116 | ChartAxis::handleAxisUpdated(); | |||
|
117 | } | |||
|
118 | ||||
109 | QTCOMMERCIALCHART_END_NAMESPACE |
|
119 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -49,8 +49,11 public: | |||||
49 | protected: |
|
49 | protected: | |
50 | QVector<qreal> calculateLayout() const; |
|
50 | QVector<qreal> calculateLayout() const; | |
51 | void updateGeometry(); |
|
51 | void updateGeometry(); | |
|
52 | Q_SLOTS | |||
|
53 | void handleAxisUpdated(); | |||
52 |
|
54 | |||
53 | private: |
|
55 | private: | |
|
56 | QStringList m_categories; | |||
54 | QBarCategoriesAxis *m_categoriesAxis; |
|
57 | QBarCategoriesAxis *m_categoriesAxis; | |
55 | }; |
|
58 | }; | |
56 |
|
59 |
@@ -105,4 +105,16 void ChartCategoriesAxisY::updateGeometry() | |||||
105 | } |
|
105 | } | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
|
108 | ||||
|
109 | void ChartCategoriesAxisY::handleAxisUpdated() | |||
|
110 | { | |||
|
111 | ||||
|
112 | if(m_categoriesAxis->categories()!=m_categories) | |||
|
113 | { | |||
|
114 | m_categories=m_categoriesAxis->categories(); | |||
|
115 | if(ChartAxis::layout().count()==m_categories.size()+1) updateGeometry(); | |||
|
116 | } | |||
|
117 | ChartAxis::handleAxisUpdated(); | |||
|
118 | } | |||
|
119 | ||||
108 | QTCOMMERCIALCHART_END_NAMESPACE |
|
120 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -49,8 +49,10 public: | |||||
49 | protected: |
|
49 | protected: | |
50 | QVector<qreal> calculateLayout() const; |
|
50 | QVector<qreal> calculateLayout() const; | |
51 | void updateGeometry(); |
|
51 | void updateGeometry(); | |
52 |
|
52 | Q_SLOTS | ||
|
53 | void handleAxisUpdated(); | |||
53 | private: |
|
54 | private: | |
|
55 | QStringList m_categories; | |||
54 | QBarCategoriesAxis *m_categoriesAxis; |
|
56 | QBarCategoriesAxis *m_categoriesAxis; | |
55 | }; |
|
57 | }; | |
56 |
|
58 |
@@ -133,7 +133,7 void QBarCategoriesAxis::append(const QStringList &categories) | |||||
133 | }else{ |
|
133 | }else{ | |
134 | d->m_categories.append(categories); |
|
134 | d->m_categories.append(categories); | |
135 | } |
|
135 | } | |
136 |
|
136 | emit d->updated(); | ||
137 | emit categoriesChanged(); |
|
137 | emit categoriesChanged(); | |
138 | } |
|
138 | } | |
139 |
|
139 | |||
@@ -149,6 +149,7 void QBarCategoriesAxis::append(const QString &category) | |||||
149 | }else{ |
|
149 | }else{ | |
150 | d->m_categories.append(category); |
|
150 | d->m_categories.append(category); | |
151 | } |
|
151 | } | |
|
152 | emit d->updated(); | |||
152 | emit categoriesChanged(); |
|
153 | emit categoriesChanged(); | |
153 | } |
|
154 | } | |
154 |
|
155 | |||
@@ -161,6 +162,7 void QBarCategoriesAxis::remove(const QString &category) | |||||
161 | if (d->m_categories.contains(category)) { |
|
162 | if (d->m_categories.contains(category)) { | |
162 | d->m_categories.removeAt(d->m_categories.indexOf(category)); |
|
163 | d->m_categories.removeAt(d->m_categories.indexOf(category)); | |
163 | setRange(d->m_categories.first(),d->m_categories.last()); |
|
164 | setRange(d->m_categories.first(),d->m_categories.last()); | |
|
165 | emit d->updated(); | |||
164 | emit categoriesChanged(); |
|
166 | emit categoriesChanged(); | |
165 | } |
|
167 | } | |
166 | } |
|
168 | } | |
@@ -177,6 +179,7 void QBarCategoriesAxis::insert(int index, const QString &category) | |||||
177 | }else{ |
|
179 | }else{ | |
178 | d->m_categories.insert(index,category); |
|
180 | d->m_categories.insert(index,category); | |
179 | } |
|
181 | } | |
|
182 | emit d->updated(); | |||
180 | emit categoriesChanged(); |
|
183 | emit categoriesChanged(); | |
181 | } |
|
184 | } | |
182 |
|
185 | |||
@@ -188,6 +191,7 void QBarCategoriesAxis::clear() | |||||
188 | Q_D(QBarCategoriesAxis); |
|
191 | Q_D(QBarCategoriesAxis); | |
189 | d->m_categories.clear(); |
|
192 | d->m_categories.clear(); | |
190 | setRange(QString::null,QString::null); |
|
193 | setRange(QString::null,QString::null); | |
|
194 | emit d->updated(); | |||
191 | emit categoriesChanged(); |
|
195 | emit categoriesChanged(); | |
192 | } |
|
196 | } | |
193 |
|
197 | |||
@@ -197,6 +201,7 void QBarCategoriesAxis::setCategories(const QStringList &categories) | |||||
197 | if(d->m_categories!=categories){ |
|
201 | if(d->m_categories!=categories){ | |
198 | d->m_categories = categories; |
|
202 | d->m_categories = categories; | |
199 | setRange(categories.first(),categories.last()); |
|
203 | setRange(categories.first(),categories.last()); | |
|
204 | emit d->updated(); | |||
200 | emit categoriesChanged(); |
|
205 | emit categoriesChanged(); | |
201 | } |
|
206 | } | |
202 | } |
|
207 | } | |
@@ -283,14 +288,14 void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& max | |||||
283 | } |
|
288 | } | |
284 |
|
289 | |||
285 | bool changed = false; |
|
290 | bool changed = false; | |
286 | if (!qFuzzyIsNull(d->m_min - (minIndex))) { |
|
291 | if (!qFuzzyIsNull(d->m_min - (minIndex))||d->m_minCategory!=minCategory) { | |
287 | d->m_minCategory = minCategory; |
|
292 | d->m_minCategory = minCategory; | |
288 | d->m_min = minIndex; |
|
293 | d->m_min = minIndex; | |
289 | emit minChanged(minCategory); |
|
294 | emit minChanged(minCategory); | |
290 | changed = true; |
|
295 | changed = true; | |
291 | } |
|
296 | } | |
292 |
|
297 | |||
293 | if (!qFuzzyIsNull(d->m_max - (maxIndex))) { |
|
298 | if (!qFuzzyIsNull(d->m_max - (maxIndex))||d->m_maxCategory!=maxCategory ) { | |
294 | d->m_max = maxIndex; |
|
299 | d->m_max = maxIndex; | |
295 | d->m_maxCategory = maxCategory; |
|
300 | d->m_maxCategory = maxCategory; | |
296 | emit maxChanged(maxCategory); |
|
301 | emit maxChanged(maxCategory); | |
@@ -299,7 +304,6 void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& max | |||||
299 |
|
304 | |||
300 | if (changed) { |
|
305 | if (changed) { | |
301 | d->emitRange(); |
|
306 | d->emitRange(); | |
302 | emit categoriesChanged(); |
|
|||
303 | } |
|
307 | } | |
304 | } |
|
308 | } | |
305 |
|
309 |
General Comments 0
You need to be logged in to leave comments.
Login now