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