##// END OF EJS Templates
Fixed a bug in setting axes dynamically via QML API
Tero Ahola -
r1947:a62b3bfbefaa
parent child
Show More
@@ -0,0 +1,75
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.1
23
24 ChartView {
25 id: chartView
26 title: "chart axes"
27
28 // TODO: Do we need a property for orientation or properties "axisX" and "axisY" on ChartView
29 // to make an axis the default axis for all series with no other axes defined...?
30 // ValueAxis {
31 // orientation: ValueAxis.AxisX
32 // min: 0
33 // max: 10
34 // }
35 // axisX: ValueAxis {
36 // min: 0
37 // max: 10
38 // }
39 // ...Now that we don't have this implementation, the following axes won't have any affect:
40 ValueAxis {
41 min: 0
42 max: 10
43 }
44 ValueAxis {
45 min: 0
46 max: 5
47 }
48
49 LineSeries {
50 name: "line series"
51 XYPoint { x: 0; y: 0 }
52 XYPoint { x: 1; y: 1 }
53 XYPoint { x: 2; y: 2 }
54 XYPoint { x: 3; y: 3 }
55 XYPoint { x: 4; y: 4 }
56 }
57
58 ScatterSeries {
59 name: "scatter series"
60 XYPoint { x: 0; y: 0 }
61 XYPoint { x: 0.5; y: 1 }
62 XYPoint { x: 1; y: 2 }
63 XYPoint { x: 1.5; y: 3 }
64 XYPoint { x: 2; y: 4 }
65 XYPoint { x: 1; y: 1 }
66 XYPoint { x: 2; y: 2 }
67 XYPoint { x: 3; y: 3 }
68 XYPoint { x: 4; y: 4 }
69 }
70
71 // Component.onCompleted: {
72 // // You can also set the axes dynamically
73 // chartView.setAxisX(axisX, scatter);
74 // }
75 }
@@ -0,0 +1,71
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.1
23
24 ChartView {
25 title: "default + user defined"
26
27 ValueAxis {
28 id: axisX
29 min: 0
30 max: 6
31 }
32
33 ValueAxis {
34 id: axisY
35 min: 0
36 max: 6
37 }
38
39 LineSeries {
40 name: "line series 1"
41 XYPoint { x: 0; y: 0 }
42 XYPoint { x: 1; y: 1 }
43 XYPoint { x: 2; y: 2 }
44 XYPoint { x: 3; y: 3 }
45 XYPoint { x: 4; y: 4 }
46 }
47
48 ScatterSeries {
49 name: "scatter series"
50 axisX: axisX
51 axisY: axisY
52 XYPoint { x: 0; y: 0 }
53 XYPoint { x: 0.5; y: 1 }
54 XYPoint { x: 1; y: 2 }
55 XYPoint { x: 1.5; y: 3 }
56 XYPoint { x: 2; y: 4 }
57 XYPoint { x: 1; y: 1 }
58 XYPoint { x: 2; y: 2 }
59 XYPoint { x: 3; y: 3 }
60 XYPoint { x: 4; y: 4 }
61 }
62
63 LineSeries {
64 name: "line series 2"
65 XYPoint { x: 0; y: 0 }
66 XYPoint { x: 0.5; y: 1 }
67 XYPoint { x: 1; y: 2 }
68 XYPoint { x: 1.5; y: 3 }
69 XYPoint { x: 2; y: 4 }
70 }
71 }
@@ -0,0 +1,64
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.1
23
24 ChartView {
25 title: "user defined reverted"
26
27 ValueAxis {
28 id: axisX
29 min: 0
30 max: 6
31 }
32
33 ValueAxis {
34 id: axisY
35 min: 0
36 max: 6
37 }
38
39 ScatterSeries {
40 name: "scatter series"
41 axisX: axisX
42 axisY: axisY
43 XYPoint { x: 0; y: 0 }
44 XYPoint { x: 0.5; y: 1 }
45 XYPoint { x: 1; y: 2 }
46 XYPoint { x: 1.5; y: 3 }
47 XYPoint { x: 2; y: 4 }
48 XYPoint { x: 1; y: 1 }
49 XYPoint { x: 2; y: 2 }
50 XYPoint { x: 3; y: 3 }
51 XYPoint { x: 4; y: 4 }
52 }
53
54 LineSeries {
55 name: "line series"
56 axisX: axisX
57 axisY: axisY
58 XYPoint { x: 0; y: 0 }
59 XYPoint { x: 1; y: 1 }
60 XYPoint { x: 2; y: 2 }
61 XYPoint { x: 3; y: 3 }
62 XYPoint { x: 4; y: 4 }
63 }
64 }
@@ -255,7 +255,7 void DeclarativeChart::componentComplete()
255 QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child);
255 QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child);
256 m_chart->addSeries(series);
256 m_chart->addSeries(series);
257
257
258 // Set optional user defined axes and connect axis related signals
258 // Set optional user defined axes for the series and connect axis related signals
259 if (qobject_cast<DeclarativeLineSeries *>(child)) {
259 if (qobject_cast<DeclarativeLineSeries *>(child)) {
260 DeclarativeLineSeries *s = qobject_cast<DeclarativeLineSeries *>(child);
260 DeclarativeLineSeries *s = qobject_cast<DeclarativeLineSeries *>(child);
261 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
261 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
@@ -317,31 +317,32 void DeclarativeChart::componentComplete()
317 setAxisX(s->axisX(), s);
317 setAxisX(s->axisX(), s);
318 setAxisY(s->axisY(), s);
318 setAxisY(s->axisY(), s);
319 }
319 }
320
321 // Create the missing axes for the series that cannot be painted without axes
322 createDefaultAxes(series);
323 } else if(qobject_cast<QAbstractAxis *>(child)) {
324 // Do nothing, axes are set for the chart in the context of series
325 }
320 }
326 }
321 }
327
322
323 // Create the missing axes for the series that cannot be painted without axes
324 foreach (QAbstractSeries *chartSeries, m_chart->series())
325 createDefaultAxes(chartSeries);
326
328 QDeclarativeItem::componentComplete();
327 QDeclarativeItem::componentComplete();
329 }
328 }
330
329
331 void DeclarativeChart::handleAxisXSet(QAbstractAxis* axis)
330 void DeclarativeChart::handleAxisXSet(QAbstractAxis* axis)
332 {
331 {
333 // qDebug() << "DeclarativeChart::handleAxisXSet" << sender() << axis;
332 // qDebug() << "DeclarativeChart::handleAxisXSet" << sender() << axis;
334 if (axis && qobject_cast<DeclarativeLineSeries *>(sender())) {
333 if (axis && qobject_cast<QAbstractSeries *>(sender()))
335 m_chart->setAxisX(axis, qobject_cast<DeclarativeLineSeries *>(sender()));
334 m_chart->setAxisX(axis, qobject_cast<QAbstractSeries *>(sender()));
336 }
335 else
336 qWarning() << "Trying to set axisX to null.";
337 }
337 }
338
338
339 void DeclarativeChart::handleAxisYSet(QAbstractAxis* axis)
339 void DeclarativeChart::handleAxisYSet(QAbstractAxis* axis)
340 {
340 {
341 // qDebug() << "DeclarativeChart::handleAxisYSet" << sender() << axis;
341 // qDebug() << "DeclarativeChart::handleAxisYSet" << sender() << axis;
342 if (axis && qobject_cast<DeclarativeLineSeries *>(sender())) {
342 if (axis && qobject_cast<QAbstractSeries *>(sender()))
343 m_chart->setAxisY(axis, qobject_cast<DeclarativeLineSeries *>(sender()));
343 m_chart->setAxisY(axis, qobject_cast<QAbstractSeries *>(sender()));
344 }
344 else
345 qWarning() << "Trying to set axisY to null.";
345 }
346 }
346
347
347 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
348 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
@@ -23,49 +23,36 import QtCommercial.Chart 1.1
23
23
24 ChartView {
24 ChartView {
25 id: chartView
25 id: chartView
26 title: "user defined axes"
26 title: "chart axes reverted"
27
27
28 ValueAxis {
28 ValueAxis {
29 id: axisX
30 min: 0
29 min: 0
31 max: 10
30 max: 10
32 // TODO: property to fix orientation to "X" to make this the X default axis for all series
33 // that don't have user defined X axis
34 }
31 }
35
36 ValueAxis {
32 ValueAxis {
37 id: axisY
38 min: 0
33 min: 0
39 max: 5
34 max: 5
40 // TODO: property to fix orientation to "Y" to make this the Y default axis for all series
41 // that don't have user defined Y axis
42 }
43
44 LineSeries {
45 name: "line series"
46 XYPoint { x: 0; y: 0 }
47 XYPoint { x: 1.1; y: 2.1 }
48 XYPoint { x: 1.9; y: 3.3 }
49 XYPoint { x: 2.1; y: 2.1 }
50 XYPoint { x: 2.9; y: 4.9 }
51 XYPoint { x: 3.4; y: 3.0 }
52 XYPoint { x: 4.1; y: 3.3 }
53 }
35 }
54
36
55 ScatterSeries {
37 ScatterSeries {
56 name: "scatter series"
38 name: "scatter series"
57 id: scatter
58 XYPoint { x: 0; y: 0 }
39 XYPoint { x: 0; y: 0 }
59 XYPoint { x: 1.1; y: 2.1 }
40 XYPoint { x: 0.5; y: 1 }
60 XYPoint { x: 1.9; y: 3.3 }
41 XYPoint { x: 1; y: 2 }
61 XYPoint { x: 2.1; y: 2.1 }
42 XYPoint { x: 1.5; y: 3 }
62 XYPoint { x: 2.9; y: 4.9 }
43 XYPoint { x: 2; y: 4 }
63 XYPoint { x: 3.4; y: 3.0 }
44 XYPoint { x: 1; y: 1 }
64 XYPoint { x: 4.1; y: 3.3 }
45 XYPoint { x: 2; y: 2 }
46 XYPoint { x: 3; y: 3 }
47 XYPoint { x: 4; y: 4 }
65 }
48 }
66
49
67 Component.onCompleted: {
50 LineSeries {
68 // You can also set the axes dynamically
51 name: "line series"
69 chartView.setAxisX(axisX, scatter);
52 XYPoint { x: 0; y: 0 }
53 XYPoint { x: 1; y: 1 }
54 XYPoint { x: 2; y: 2 }
55 XYPoint { x: 3; y: 3 }
56 XYPoint { x: 4; y: 4 }
70 }
57 }
71 }
58 }
@@ -33,16 +33,16 ChartView {
33 onTriggered: {
33 onTriggered: {
34 switch (index) {
34 switch (index) {
35 case 0:
35 case 0:
36 chartView.axisX(lineSeries).max = 5;
36 chartView.axisX(lineSeries).max = 6;
37 chartView.axisY(lineSeries).max = 5;
37 chartView.axisY(lineSeries).max = 6;
38 break;
38 break;
39 case 1:
39 case 1:
40 chartView.axisX(scatterSeries).max = 10;
40 chartView.axisX(scatterSeries).max = 10;
41 chartView.axisY(scatterSeries).max = 10;
41 chartView.axisY(scatterSeries).max = 10;
42 break;
42 break;
43 default:
43 default:
44 chartView.axisX().max = 15;
44 chartView.axisX().max = 4;
45 chartView.axisY().max = 15;
45 chartView.axisY().max = 4;
46 }
46 }
47 index = (index + 1) % 3;
47 index = (index + 1) % 3;
48 }
48 }
@@ -52,23 +52,23 ChartView {
52 id: lineSeries
52 id: lineSeries
53 name: "line series"
53 name: "line series"
54 XYPoint { x: 0; y: 0 }
54 XYPoint { x: 0; y: 0 }
55 XYPoint { x: 1.1; y: 2.1 }
55 XYPoint { x: 1; y: 1 }
56 XYPoint { x: 1.9; y: 3.3 }
56 XYPoint { x: 2; y: 2 }
57 XYPoint { x: 2.1; y: 2.1 }
57 XYPoint { x: 3; y: 3 }
58 XYPoint { x: 2.9; y: 4.9 }
58 XYPoint { x: 4; y: 4 }
59 XYPoint { x: 3.4; y: 3.0 }
60 XYPoint { x: 4.1; y: 3.3 }
61 }
59 }
62
60
63 ScatterSeries {
61 ScatterSeries {
64 id: scatterSeries
62 id: scatterSeries
65 name: "scatter series"
63 name: "scatter series"
66 XYPoint { x: 0; y: 0 }
64 XYPoint { x: 0; y: 0 }
67 XYPoint { x: 1.1; y: 2.1 }
65 XYPoint { x: 0.5; y: 1 }
68 XYPoint { x: 1.9; y: 3.3 }
66 XYPoint { x: 1; y: 2 }
69 XYPoint { x: 2.1; y: 2.1 }
67 XYPoint { x: 1.5; y: 3 }
70 XYPoint { x: 2.9; y: 4.9 }
68 XYPoint { x: 2; y: 4 }
71 XYPoint { x: 3.4; y: 3.0 }
69 XYPoint { x: 1; y: 1 }
72 XYPoint { x: 4.1; y: 3.3 }
70 XYPoint { x: 2; y: 2 }
71 XYPoint { x: 3; y: 3 }
72 XYPoint { x: 4; y: 4 }
73 }
73 }
74 }
74 }
@@ -23,7 +23,7 import QtCommercial.Chart 1.1
23
23
24 ChartView {
24 ChartView {
25 id: chartView
25 id: chartView
26 title: "dynamically created series"
26 title: "creating dyn. new series"
27 property int index: 0
27 property int index: 0
28
28
29 Timer {
29 Timer {
@@ -33,16 +33,16 ChartView {
33 onTriggered: {
33 onTriggered: {
34 switch (index) {
34 switch (index) {
35 case 0:
35 case 0:
36 while (chartView.count)
36 while (chartView.count) {
37 console.log("Destroying series. Count: " + chartView.count);
37 chartView.series(0).destroy();
38 chartView.series(0).destroy();
39 }
38 var line = chartView.createSeries(ChartView.SeriesTypeLine, "line");
40 var line = chartView.createSeries(ChartView.SeriesTypeLine, "line");
39 line.append(0, 0);
41 line.append(0, 0);
40 line.append(1.1, 2.1);
42 line.append(1, 1);
41 line.append(1.9, 3.3);
43 line.append(2, 2);
42 line.append(2.1, 2.1);
44 line.append(3, 3);
43 line.append(2.9, 4.9);
45 line.append(4, 4);
44 line.append(3.4, 3.0);
45 line.append(4.1, 3.3);
46 break;
46 break;
47 case 1:
47 case 1:
48 chartView.axisX().min = 0;
48 chartView.axisX().min = 0;
@@ -53,12 +53,14 ChartView {
53 default:
53 default:
54 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter");
54 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter");
55 scatter.append(0, 0);
55 scatter.append(0, 0);
56 scatter.append(1.1, 2.1);
56 scatter.append(0.5, 1);
57 scatter.append(1.9, 3.3);
57 scatter.append(1, 2);
58 scatter.append(2.1, 2.1);
58 scatter.append(1.5, 3);
59 scatter.append(2.9, 4.9);
59 scatter.append(2, 4);
60 scatter.append(3.4, 3.0);
60 scatter.append(1, 1);
61 scatter.append(4.1, 3.3);
61 scatter.append(2, 2);
62 scatter.append(3, 3);
63 scatter.append(4, 4);
62 }
64 }
63 index = (index + 1) % 3;
65 index = (index + 1) % 3;
64 }
66 }
@@ -28,22 +28,22 ChartView {
28 LineSeries {
28 LineSeries {
29 name: "line series"
29 name: "line series"
30 XYPoint { x: 0; y: 0 }
30 XYPoint { x: 0; y: 0 }
31 XYPoint { x: 1.1; y: 2.1 }
31 XYPoint { x: 1; y: 1 }
32 XYPoint { x: 1.9; y: 3.3 }
32 XYPoint { x: 2; y: 2 }
33 XYPoint { x: 2.1; y: 2.1 }
33 XYPoint { x: 3; y: 3 }
34 XYPoint { x: 2.9; y: 4.9 }
34 XYPoint { x: 4; y: 4 }
35 XYPoint { x: 3.4; y: 3.0 }
36 XYPoint { x: 4.1; y: 3.3 }
37 }
35 }
38
36
39 ScatterSeries {
37 ScatterSeries {
40 name: "scatter series"
38 name: "scatter series"
41 XYPoint { x: 0; y: 0 }
39 XYPoint { x: 0; y: 0 }
42 XYPoint { x: 1.1; y: 2.1 }
40 XYPoint { x: 0.5; y: 1 }
43 XYPoint { x: 1.9; y: 3.3 }
41 XYPoint { x: 1; y: 2 }
44 XYPoint { x: 2.1; y: 2.1 }
42 XYPoint { x: 1.5; y: 3 }
45 XYPoint { x: 2.9; y: 4.9 }
43 XYPoint { x: 2; y: 4 }
46 XYPoint { x: 3.4; y: 3.0 }
44 XYPoint { x: 1; y: 1 }
47 XYPoint { x: 4.1; y: 3.3 }
45 XYPoint { x: 2; y: 2 }
46 XYPoint { x: 3; y: 3 }
47 XYPoint { x: 4; y: 4 }
48 }
48 }
49 }
49 }
@@ -23,21 +23,27 import QtCommercial.Chart 1.1
23
23
24 ChartView {
24 ChartView {
25 id: chartView
25 id: chartView
26 title: "axis scale; different series"
26 title: "default axes"
27
27
28 LineSeries {
28 ScatterSeries {
29 name: "line series"
29 name: "scatter series"
30 XYPoint { x: 0; y: 0 }
30 XYPoint { x: 0; y: 0 }
31 XYPoint { x: 1.1; y: 2.1 }
31 XYPoint { x: 0.5; y: 1 }
32 XYPoint { x: 1.9; y: 3.3 }
32 XYPoint { x: 1; y: 2 }
33 XYPoint { x: 2.1; y: 2.1 }
33 XYPoint { x: 1.5; y: 3 }
34 XYPoint { x: 2; y: 4 }
35 XYPoint { x: 1; y: 1 }
36 XYPoint { x: 2; y: 2 }
37 XYPoint { x: 3; y: 3 }
38 XYPoint { x: 4; y: 4 }
34 }
39 }
35
40
36 ScatterSeries {
41 LineSeries {
37 name: "scatter series"
42 name: "line series"
38 XYPoint { x: 2.1; y: 2.1 }
43 XYPoint { x: 0; y: 0 }
39 XYPoint { x: 2.9; y: 4.9 }
44 XYPoint { x: 1; y: 1 }
40 XYPoint { x: 3.4; y: 3.0 }
45 XYPoint { x: 2; y: 2 }
41 XYPoint { x: 4.1; y: 3.3 }
46 XYPoint { x: 3; y: 3 }
47 XYPoint { x: 4; y: 4 }
42 }
48 }
43 }
49 }
@@ -35,22 +35,22 ChartView {
35 LineSeries {
35 LineSeries {
36 name: "line series"
36 name: "line series"
37 XYPoint { x: 0; y: 0 }
37 XYPoint { x: 0; y: 0 }
38 XYPoint { x: 1.1; y: 2.1 }
38 XYPoint { x: 1; y: 1 }
39 XYPoint { x: 1.9; y: 3.3 }
39 XYPoint { x: 2; y: 2 }
40 XYPoint { x: 2.1; y: 2.1 }
40 XYPoint { x: 3; y: 3 }
41 XYPoint { x: 2.9; y: 4.9 }
41 XYPoint { x: 4; y: 4 }
42 XYPoint { x: 3.4; y: 3.0 }
43 XYPoint { x: 4.1; y: 3.3 }
44 }
42 }
45
43
46 ScatterSeries {
44 ScatterSeries {
47 name: "scatter series"
45 name: "scatter series"
48 XYPoint { x: 0; y: 0 }
46 XYPoint { x: 0; y: 0 }
49 XYPoint { x: 1.1; y: 2.1 }
47 XYPoint { x: 0.5; y: 1 }
50 XYPoint { x: 1.9; y: 3.3 }
48 XYPoint { x: 1; y: 2 }
51 XYPoint { x: 2.1; y: 2.1 }
49 XYPoint { x: 1.5; y: 3 }
52 XYPoint { x: 2.9; y: 4.9 }
50 XYPoint { x: 2; y: 4 }
53 XYPoint { x: 3.4; y: 3.0 }
51 XYPoint { x: 1; y: 1 }
54 XYPoint { x: 4.1; y: 3.3 }
52 XYPoint { x: 2; y: 2 }
53 XYPoint { x: 3; y: 3 }
54 XYPoint { x: 4; y: 4 }
55 }
55 }
56 }
56 }
@@ -33,20 +33,20 ChartView {
33 onTriggered: {
33 onTriggered: {
34 switch (index) {
34 switch (index) {
35 case 0:
35 case 0:
36 lineAxisX.max = 5;
36 lineAxisX.max = 6;
37 lineAxisY.max = 5;
37 lineAxisY.max = 6;
38 scatterAxisX.max = 10;
38 scatterAxisX.max = 10;
39 scatterAxisY.max = 10;
39 scatterAxisY.max = 10;
40 break;
40 break;
41 case 1:
41 case 1:
42 lineAxisX.max = 10;
42 lineAxisX.max = 10;
43 lineAxisY.max = 10;
43 lineAxisY.max = 10;
44 scatterAxisX.max = 5;
44 scatterAxisX.max = 6;
45 scatterAxisY.max = 5;
45 scatterAxisY.max = 6;
46 break;
46 break;
47 default:
47 default:
48 chartView.axisX().max = 2;
48 chartView.axisX().max = 4;
49 chartView.axisY().max = 2;
49 chartView.axisY().max = 4;
50 }
50 }
51 index = (index + 1) % 3;
51 index = (index + 1) % 3;
52 }
52 }
@@ -57,14 +57,11 ChartView {
57 name: "line series"
57 name: "line series"
58 axisX: ValueAxis { id: lineAxisX }
58 axisX: ValueAxis { id: lineAxisX }
59 axisY: ValueAxis { id: lineAxisY }
59 axisY: ValueAxis { id: lineAxisY }
60
61 XYPoint { x: 0; y: 0 }
60 XYPoint { x: 0; y: 0 }
62 XYPoint { x: 1.1; y: 2.1 }
61 XYPoint { x: 1; y: 1 }
63 XYPoint { x: 1.9; y: 3.3 }
62 XYPoint { x: 2; y: 2 }
64 XYPoint { x: 2.1; y: 2.1 }
63 XYPoint { x: 3; y: 3 }
65 XYPoint { x: 2.9; y: 4.9 }
64 XYPoint { x: 4; y: 4 }
66 XYPoint { x: 3.4; y: 3.0 }
67 XYPoint { x: 4.1; y: 3.3 }
68 }
65 }
69
66
70 ScatterSeries {
67 ScatterSeries {
@@ -72,13 +69,14 ChartView {
72 name: "scatter series"
69 name: "scatter series"
73 axisX: ValueAxis { id: scatterAxisX }
70 axisX: ValueAxis { id: scatterAxisX }
74 axisY: ValueAxis { id: scatterAxisY }
71 axisY: ValueAxis { id: scatterAxisY }
75
76 XYPoint { x: 0; y: 0 }
72 XYPoint { x: 0; y: 0 }
77 XYPoint { x: 1.1; y: 2.1 }
73 XYPoint { x: 0.5; y: 1 }
78 XYPoint { x: 1.9; y: 3.3 }
74 XYPoint { x: 1; y: 2 }
79 XYPoint { x: 2.1; y: 2.1 }
75 XYPoint { x: 1.5; y: 3 }
80 XYPoint { x: 2.9; y: 4.9 }
76 XYPoint { x: 2; y: 4 }
81 XYPoint { x: 3.4; y: 3.0 }
77 XYPoint { x: 1; y: 1 }
82 XYPoint { x: 4.1; y: 3.3 }
78 XYPoint { x: 2; y: 2 }
79 XYPoint { x: 3; y: 3 }
80 XYPoint { x: 4; y: 4 }
83 }
81 }
84 }
82 }
@@ -30,10 +30,13 ChartView {
30 repeat: true
30 repeat: true
31 running: true
31 running: true
32 onTriggered: {
32 onTriggered: {
33 //console.log("current axisX: " + lineSeries.axisX + " 1: " + valueAxis1 + " 2: " +valueAxis2);
34
35 // Note: an axis is destroyed if it is not used anymore
33 if (lineSeries.axisX == valueAxis1)
36 if (lineSeries.axisX == valueAxis1)
34 lineSeries.axisX = valueAxis2;
37 lineSeries.axisX = valueAxis2;
35 else
38 else if (lineSeries.axisX == valueAxis2)
36 lineSeries.axisX = valueAxis1;
39 lineSeries.axisX = valueAxis3;
37 }
40 }
38 }
41 }
39
42
@@ -49,16 +52,20 ChartView {
49 max: 6
52 max: 6
50 }
53 }
51
54
55 ValueAxis {
56 id: valueAxis3
57 min: 2
58 max: 7
59 }
60
52 LineSeries {
61 LineSeries {
53 id: lineSeries
62 id: lineSeries
54 name: "line series"
63 name: "line series"
55 axisX: valueAxis1
64 axisX: valueAxis1
56 XYPoint { x: 0; y: 0 }
65 XYPoint { x: 0; y: 0 }
57 XYPoint { x: 1.1; y: 2.1 }
66 XYPoint { x: 1; y: 1 }
58 XYPoint { x: 1.9; y: 3.3 }
67 XYPoint { x: 2; y: 2 }
59 XYPoint { x: 2.1; y: 2.1 }
68 XYPoint { x: 3; y: 3 }
60 XYPoint { x: 2.9; y: 4.9 }
69 XYPoint { x: 4; y: 4 }
61 XYPoint { x: 3.4; y: 3.0 }
62 XYPoint { x: 4.1; y: 3.3 }
63 }
70 }
64 }
71 }
@@ -22,12 +22,12 import QtQuick 1.0
22 import QtCommercial.Chart 1.1
22 import QtCommercial.Chart 1.1
23
23
24 ChartView {
24 ChartView {
25 title: "user defined axes"
25 title: "user defined"
26
26
27 ValueAxis {
27 ValueAxis {
28 id: axisX
28 id: axisX
29 min: 0
29 min: 0
30 max: 10
30 max: 6
31 }
31 }
32
32
33 ValueAxis {
33 ValueAxis {
@@ -41,12 +41,10 ChartView {
41 axisX: axisX
41 axisX: axisX
42 axisY: axisY
42 axisY: axisY
43 XYPoint { x: 0; y: 0 }
43 XYPoint { x: 0; y: 0 }
44 XYPoint { x: 1.1; y: 2.1 }
44 XYPoint { x: 1; y: 1 }
45 XYPoint { x: 1.9; y: 3.3 }
45 XYPoint { x: 2; y: 2 }
46 XYPoint { x: 2.1; y: 2.1 }
46 XYPoint { x: 3; y: 3 }
47 XYPoint { x: 2.9; y: 4.9 }
47 XYPoint { x: 4; y: 4 }
48 XYPoint { x: 3.4; y: 3.0 }
49 XYPoint { x: 4.1; y: 3.3 }
50 }
48 }
51
49
52 ScatterSeries {
50 ScatterSeries {
@@ -54,11 +52,13 ChartView {
54 axisX: axisX
52 axisX: axisX
55 axisY: axisY
53 axisY: axisY
56 XYPoint { x: 0; y: 0 }
54 XYPoint { x: 0; y: 0 }
57 XYPoint { x: 1.1; y: 2.1 }
55 XYPoint { x: 0.5; y: 1 }
58 XYPoint { x: 1.9; y: 3.3 }
56 XYPoint { x: 1; y: 2 }
59 XYPoint { x: 2.1; y: 2.1 }
57 XYPoint { x: 1.5; y: 3 }
60 XYPoint { x: 2.9; y: 4.9 }
58 XYPoint { x: 2; y: 4 }
61 XYPoint { x: 3.4; y: 3.0 }
59 XYPoint { x: 1; y: 1 }
62 XYPoint { x: 4.1; y: 3.3 }
60 XYPoint { x: 2; y: 2 }
61 XYPoint { x: 3; y: 3 }
62 XYPoint { x: 4; y: 4 }
63 }
63 }
64 }
64 }
@@ -24,7 +24,7 Rectangle {
24 id: main
24 id: main
25 width: 400
25 width: 400
26 height: 300
26 height: 300
27 property int viewNumber: 0
27 property string viewName: "DefaultAxes"
28
28
29 Row {
29 Row {
30 anchors.fill: parent
30 anchors.fill: parent
@@ -34,7 +34,7 Rectangle {
34 id: chartLoader
34 id: chartLoader
35 width: parent.width - buttonColumn.width
35 width: parent.width - buttonColumn.width
36 height: parent.height
36 height: parent.height
37 source: "Chart" + viewNumber + ".qml"
37 source: viewName + ".qml"
38 }
38 }
39
39
40 Column {
40 Column {
@@ -44,40 +44,52 Rectangle {
44 spacing: 5
44 spacing: 5
45
45
46 Button {
46 Button {
47 text: "Default"
47 text: "Default axes"
48 onClicked: viewNumber = 0;
48 onClicked: viewName = "DefaultAxes";
49 }
50 Button {
51 text: "Default axes reverted"
52 onClicked: viewName = "DefaultAxesRevert";
49 }
53 }
50 Button {
54 Button {
51 text: "User defined"
55 text: "User defined"
52 onClicked: viewNumber = 1;
56 onClicked: viewName = "UserDefined";
57 }
58 Button {
59 text: "User defined reverted"
60 onClicked: viewName = "UserDefinedRevert";
53 }
61 }
54 Button {
62 Button {
55 text: "Chart axes"
63 text: "Chart axes"
56 onClicked: viewNumber = 2;
64 onClicked: viewName = "ChartAxes";
65 }
66 Button {
67 text: "Chart axes reverted"
68 onClicked: viewName = "ChartAxesRevert";
57 }
69 }
58 Button {
70 Button {
59 text: "Configuring dynamically"
71 text: "Configuring dynamically"
60 onClicked: viewNumber = 3;
72 onClicked: viewName = "ConfiguringDynamically";
61 }
73 }
62 Button {
74 Button {
63 text: "Series specific dynamic"
75 text: "Series specific dynamic"
64 onClicked: viewNumber = 4;
76 onClicked: viewName = "SeriesSpecificDynamic";
65 }
77 }
66 Button {
78 Button {
67 text: "Creating dynamically"
79 text: "Creating dynamically"
68 onClicked: viewNumber = 5;
80 onClicked: viewName = "CreatingDynamically";
69 }
81 }
70 Button {
82 Button {
71 text: "Switching dynamically"
83 text: "Switching dynamically"
72 onClicked: viewNumber = 6;
84 onClicked: viewName = "SwitchingDynamically";
73 }
85 }
74 Button {
86 Button {
75 text: "Axis scale"
87 text: "Default + User defined"
76 onClicked: viewNumber = 7;
88 onClicked: viewName = "DefaultAndUserDefined";
77 }
89 }
78 Button {
90 Button {
79 text: "Legacy"
91 text: "Legacy"
80 onClicked: viewNumber = 8;
92 onClicked: viewName = "Legacy";
81 }
93 }
82 }
94 }
83 }
95 }
@@ -2,14 +2,17
2 <qresource prefix="/">
2 <qresource prefix="/">
3 <file>qml/qmlchartaxis/main.qml</file>
3 <file>qml/qmlchartaxis/main.qml</file>
4 <file>qml/qmlchartaxis/Button.qml</file>
4 <file>qml/qmlchartaxis/Button.qml</file>
5 <file>qml/qmlchartaxis/Chart0.qml</file>
5 <file>qml/qmlchartaxis/DefaultAxes.qml</file>
6 <file>qml/qmlchartaxis/Chart1.qml</file>
6 <file>qml/qmlchartaxis/DefaultAxesRevert.qml</file>
7 <file>qml/qmlchartaxis/Chart2.qml</file>
7 <file>qml/qmlchartaxis/UserDefined.qml</file>
8 <file>qml/qmlchartaxis/Chart3.qml</file>
8 <file>qml/qmlchartaxis/UserDefinedRevert.qml</file>
9 <file>qml/qmlchartaxis/Chart4.qml</file>
9 <file>qml/qmlchartaxis/ChartAxes.qml</file>
10 <file>qml/qmlchartaxis/Chart5.qml</file>
10 <file>qml/qmlchartaxis/ChartAxesRevert.qml</file>
11 <file>qml/qmlchartaxis/Chart6.qml</file>
11 <file>qml/qmlchartaxis/ConfiguringDynamically.qml</file>
12 <file>qml/qmlchartaxis/Chart7.qml</file>
12 <file>qml/qmlchartaxis/SeriesSpecificDynamic.qml</file>
13 <file>qml/qmlchartaxis/Chart8.qml</file>
13 <file>qml/qmlchartaxis/CreatingDynamically.qml</file>
14 <file>qml/qmlchartaxis/SwitchingDynamically.qml</file>
15 <file>qml/qmlchartaxis/DefaultAndUserDefined.qml</file>
16 <file>qml/qmlchartaxis/Legacy.qml</file>
14 </qresource>
17 </qresource>
15 </RCC>
18 </RCC>
General Comments 0
You need to be logged in to leave comments. Login now