##// END OF EJS Templates
QML: Added possibility to define axes when creating series
Tero Ahola -
r1960:bd364d589414
parent child
Show More
@@ -25,6 +25,7 import QtCommercial.Chart 1.1
25 25 ChartView {
26 26 id: chartView
27 27 animationOptions: ChartView.NoAnimation
28 theme: ChartView.ChartThemeDark
28 29
29 30 ValueAxis {
30 31 id: axisY1
@@ -72,24 +73,36 ChartView {
72 73 }
73 74 //![2]
74 75
76 //![3]
75 77 function changeSeriesType(type) {
76 chartView.series(1).destroy();
77 chartView.series(0).destroy();
78 var seriesCount = 2;
79 for (var i = 0; i < seriesCount; i++) {
80 var series;
81 if (type == "line") {
82 series = scopeView.createSeries(ChartView.SeriesTypeLine, "signal " + (i + 1));
83 } else if (type == "spline") {
84 series = chartView.createSeries(ChartView.SeriesTypeSpline, "signal " + (i + 1));
85 } else {
86 series = chartView.createSeries(ChartView.SeriesTypeScatter, "signal " + (i + 1));
87 series.markerSize = 3;
88 series.borderColor = "transparent";
89 }
78 chartView.removeAllSeries();
79
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
82 // of the "signal sources".
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));
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));
89 } else {
90 var series1 = scopeView.createSeries(ChartView.SeriesTypeScatter, "signal 1", createAxis(0, 1000), createAxis(-1, 4));
91 series1.markerSize = 3;
92 series1.borderColor = "transparent";
93 var series2 = scopeView.createSeries(ChartView.SeriesTypeScatter, "signal 2", chartView.axisX(), createAxis(-10, 5));
94 series2.markerSize = 3;
95 series2.borderColor = "transparent";
90 96 }
91 97 }
92 98
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
101 return Qt.createQmlObject("import QtQuick 1.1; import QtCommercial.Chart 1.1; ValueAxis { min: "
102 + min + "; max: " + max + " }", chartView);
103 }
104 //![3]
105
93 106 function setAnimations(enabled) {
94 107 if (enabled)
95 108 scopeView.animationOptions = ChartView.SeriesAnimations;
1 NO CONTENT: modified file, binary diff hidden
@@ -24,4 +24,8
24 24 The data of the line series is updated with a QML timer. In a real life application the
25 25 updating could triggered with a signal from Qt C++ code.
26 26 \snippet ../demos/qmloscilloscope/qml/qmloscilloscope/ScopeView.qml 2
27
28 The oscilloscope also allows you to switch the type of the series used for visualizing the
29 signal sources. This is implemented by dynamically destroying and creating series:
30 \snippet ../demos/qmloscilloscope/qml/qmloscilloscope/ScopeView.qml 3
27 31 */
@@ -164,12 +164,14 QTCOMMERCIALCHART_BEGIN_NAMESPACE
164 164 */
165 165
166 166 /*!
167 \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name)
168 Creates a series object of \a type to the chart. For example:
167 \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY)
168 Creates a series object of \a type to the chart with name \a name, optional axis \a axisX and
169 optional axis \a axisY. For example:
169 170 \code
170 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series");
171 scatter.markerSize = 22;
172 scatter.append(1.1, 2.0);
171 // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes
172 var myAxisX = chartView.axisX(lineSeries);
173 var myAxisY = chartView.axisY(lineSeries);
174 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY);
173 175 \endcode
174 176 */
175 177
@@ -184,8 +186,13 QTCOMMERCIALCHART_BEGIN_NAMESPACE
184 186 */
185 187
186 188 /*!
189 \qmlmethod Axis ChartView::axisX(QAbstractSeries *series)
190 The x-axis of the series.
191 */
192
193 /*!
187 194 \qmlmethod Axis ChartView::axisY(QAbstractSeries *series)
188 The y-axis of the series. This is the same as the default y-axis of the chart as multiple y-axes are not yet supported.
195 The y-axis of the series.
189 196 */
190 197
191 198 /*!
@@ -554,6 +561,11 QAbstractSeries *DeclarativeChart::series(QString seriesName)
554 561
555 562 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name)
556 563 {
564 return createSeries(type, name, 0, 0);
565 }
566
567 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY)
568 {
557 569 QAbstractSeries *series = 0;
558 570
559 571 switch (type) {
@@ -597,6 +609,10 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType typ
597 609 if (series) {
598 610 series->setName(name);
599 611 m_chart->addSeries(series);
612 // Set possible user defined axes
613 setAxisX(axisX, series);
614 setAxisY(axisY, series);
615 // Then create the missing axes
600 616 createDefaultAxes(series);
601 617 }
602 618
@@ -122,6 +122,7 public:
122 122 Q_INVOKABLE QAbstractSeries *series(int index);
123 123 Q_INVOKABLE QAbstractSeries *series(QString seriesName);
124 124 Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = "");
125 Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY);
125 126 Q_INVOKABLE void removeSeries(QAbstractSeries *series) { m_chart->removeSeries(series); }
126 127 Q_INVOKABLE void removeAllSeries() { m_chart->removeAllSeries(); }
127 128 Q_INVOKABLE void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0);
General Comments 0
You need to be logged in to leave comments. Login now