@@ -1,116 +1,116 | |||||
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 | import QtQuick 1.0 |
|
21 | import QtQuick 1.0 | |
22 | import QtCommercial.Chart 1.1 |
|
22 | import QtCommercial.Chart 1.1 | |
23 |
|
23 | |||
24 | //![1] |
|
24 | //![1] | |
25 | ChartView { |
|
25 | ChartView { | |
26 | id: chartView |
|
26 | id: chartView | |
27 | animationOptions: ChartView.NoAnimation |
|
27 | animationOptions: ChartView.NoAnimation | |
28 | theme: ChartView.ChartThemeDark |
|
28 | theme: ChartView.ChartThemeDark | |
29 |
|
29 | |||
30 | ValueAxis { |
|
30 | ValueAxis { | |
31 | id: axisY1 |
|
31 | id: axisY1 | |
32 | min: -1 |
|
32 | min: -1 | |
33 | max: 4 |
|
33 | max: 4 | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | ValueAxis { |
|
36 | ValueAxis { | |
37 | id: axisY2 |
|
37 | id: axisY2 | |
38 | min: -10 |
|
38 | min: -10 | |
39 | max: 5 |
|
39 | max: 5 | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | ValueAxis { |
|
42 | ValueAxis { | |
43 | id: axisX |
|
43 | id: axisX | |
44 | min: 0 |
|
44 | min: 0 | |
45 | max: 1000 |
|
45 | max: 1000 | |
46 | } |
|
46 | } | |
47 |
|
47 | |||
48 | LineSeries { |
|
48 | LineSeries { | |
49 | id: lineSeries1 |
|
49 | id: lineSeries1 | |
50 | name: "signal 1" |
|
50 | name: "signal 1" | |
51 | axisX: axisX |
|
51 | axisX: axisX | |
52 | axisY: axisY1 |
|
52 | axisY: axisY1 | |
53 | } |
|
53 | } | |
54 | LineSeries { |
|
54 | LineSeries { | |
55 | id: lineSeries2 |
|
55 | id: lineSeries2 | |
56 | name: "signal 2" |
|
56 | name: "signal 2" | |
57 | axisX: axisX |
|
57 | axisX: axisX | |
58 | axisY: axisY2 |
|
58 | axisY: axisY2 | |
59 | } |
|
59 | } | |
60 | // ... |
|
60 | // ... | |
61 | //![1] |
|
61 | //![1] | |
62 |
|
62 | |||
63 | //![2] |
|
63 | //![2] | |
64 | Timer { |
|
64 | Timer { | |
65 | id: refreshTimer |
|
65 | id: refreshTimer | |
66 | interval: 1 / 60 * 1000 // 60 Hz |
|
66 | interval: 1 / 60 * 1000 // 60 Hz | |
67 | running: true |
|
67 | running: true | |
68 | repeat: true |
|
68 | repeat: true | |
69 | onTriggered: { |
|
69 | onTriggered: { | |
70 | dataSource.update(chartView.series(0)); |
|
70 | dataSource.update(chartView.series(0)); | |
71 | dataSource.update(chartView.series(1)); |
|
71 | dataSource.update(chartView.series(1)); | |
72 | } |
|
72 | } | |
73 | } |
|
73 | } | |
74 | //![2] |
|
74 | //![2] | |
75 |
|
75 | |||
76 | //![3] |
|
76 | //![3] | |
77 | function changeSeriesType(type) { |
|
77 | function changeSeriesType(type) { | |
78 | chartView.removeAllSeries(); |
|
78 | chartView.removeAllSeries(); | |
79 |
|
79 | |||
80 | // Create two new series of the correct type. Axis x is the same for both of the series, |
|
80 | // Create two new series of the correct type. Axis x is the same for both of the series, | |
81 | // but the series have their own y-axes to make it possible to control the y-offset |
|
81 | // but the series have their own y-axes to make it possible to control the y-offset | |
82 | // of the "signal sources". |
|
82 | // of the "signal sources". | |
83 | if (type == "line") { |
|
83 | if (type == "line") { | |
84 |
scopeView.createSeries(ChartView.SeriesTypeLine, "signal 1", |
|
84 | scopeView.createSeries(ChartView.SeriesTypeLine, "signal 1", axisX, axisY1); | |
85 |
scopeView.createSeries(ChartView.SeriesTypeLine, "signal 2", |
|
85 | scopeView.createSeries(ChartView.SeriesTypeLine, "signal 2", axisX, axisY2); | |
86 | } else if (type == "spline") { |
|
86 | } else if (type == "spline") { | |
87 |
scopeView.createSeries(ChartView.SeriesTypeSpline, "signal 1", |
|
87 | scopeView.createSeries(ChartView.SeriesTypeSpline, "signal 1", axisX, axisY1); | |
88 |
scopeView.createSeries(ChartView.SeriesTypeSpline, "signal 2", |
|
88 | scopeView.createSeries(ChartView.SeriesTypeSpline, "signal 2", axisX, axisY2); | |
89 | } else { |
|
89 | } else { | |
90 |
var series1 = scopeView.createSeries(ChartView.SeriesTypeScatter, "signal 1", |
|
90 | var series1 = scopeView.createSeries(ChartView.SeriesTypeScatter, "signal 1", axisX, axisY1); | |
91 | series1.markerSize = 3; |
|
91 | series1.markerSize = 3; | |
92 | series1.borderColor = "transparent"; |
|
92 | series1.borderColor = "transparent"; | |
93 |
var series2 = scopeView.createSeries(ChartView.SeriesTypeScatter, "signal 2", |
|
93 | var series2 = scopeView.createSeries(ChartView.SeriesTypeScatter, "signal 2", axisX, axisY2); | |
94 | series2.markerSize = 3; |
|
94 | series2.markerSize = 3; | |
95 | series2.borderColor = "transparent"; |
|
95 | series2.borderColor = "transparent"; | |
96 | } |
|
96 | } | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | function createAxis(min, max) { |
|
99 | function createAxis(min, max) { | |
100 | // The following creates a ValueAxis object that can be then set as a x or y axis for a series |
|
100 | // The following creates a ValueAxis object that can be then set as a x or y axis for a series | |
101 | return Qt.createQmlObject("import QtQuick 1.1; import QtCommercial.Chart 1.1; ValueAxis { min: " |
|
101 | return Qt.createQmlObject("import QtQuick 1.1; import QtCommercial.Chart 1.1; ValueAxis { min: " | |
102 | + min + "; max: " + max + " }", chartView); |
|
102 | + min + "; max: " + max + " }", chartView); | |
103 | } |
|
103 | } | |
104 | //![3] |
|
104 | //![3] | |
105 |
|
105 | |||
106 | function setAnimations(enabled) { |
|
106 | function setAnimations(enabled) { | |
107 | if (enabled) |
|
107 | if (enabled) | |
108 | scopeView.animationOptions = ChartView.SeriesAnimations; |
|
108 | scopeView.animationOptions = ChartView.SeriesAnimations; | |
109 | else |
|
109 | else | |
110 | scopeView.animationOptions = ChartView.NoAnimation; |
|
110 | scopeView.animationOptions = ChartView.NoAnimation; | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | function changeRefreshRate(rate) { |
|
113 | function changeRefreshRate(rate) { | |
114 | refreshTimer.interval = 1 / Number(rate) * 1000; |
|
114 | refreshTimer.interval = 1 / Number(rate) * 1000; | |
115 | } |
|
115 | } | |
116 | } |
|
116 | } |
General Comments 0
You need to be logged in to leave comments.
Login now