##// 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 ChartView {
25 ChartView {
26 id: chartView
26 id: chartView
27 animationOptions: ChartView.NoAnimation
27 animationOptions: ChartView.NoAnimation
28 theme: ChartView.ChartThemeDark
28
29
29 ValueAxis {
30 ValueAxis {
30 id: axisY1
31 id: axisY1
@@ -72,23 +73,35 ChartView {
72 }
73 }
73 //![2]
74 //![2]
74
75
76 //![3]
75 function changeSeriesType(type) {
77 function changeSeriesType(type) {
76 chartView.series(1).destroy();
78 chartView.removeAllSeries();
77 chartView.series(0).destroy();
79
78 var seriesCount = 2;
80 // Create two new series of the correct type. Axis x is the same for both of the series,
79 for (var i = 0; i < seriesCount; i++) {
81 // but the series have their own y-axes to make it possible to control the y-offset
80 var series;
82 // of the "signal sources".
81 if (type == "line") {
83 if (type == "line") {
82 series = scopeView.createSeries(ChartView.SeriesTypeLine, "signal " + (i + 1));
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));
83 } else if (type == "spline") {
86 } else if (type == "spline") {
84 series = chartView.createSeries(ChartView.SeriesTypeSpline, "signal " + (i + 1));
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));
85 } else {
89 } else {
86 series = chartView.createSeries(ChartView.SeriesTypeScatter, "signal " + (i + 1));
90 var series1 = scopeView.createSeries(ChartView.SeriesTypeScatter, "signal 1", createAxis(0, 1000), createAxis(-1, 4));
87 series.markerSize = 3;
91 series1.markerSize = 3;
88 series.borderColor = "transparent";
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";
89 }
96 }
90 }
97 }
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);
91 }
103 }
104 //![3]
92
105
93 function setAnimations(enabled) {
106 function setAnimations(enabled) {
94 if (enabled)
107 if (enabled)
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -24,4 +24,8
24 The data of the line series is updated with a QML timer. In a real life application the
24 The data of the line series is updated with a QML timer. In a real life application the
25 updating could triggered with a signal from Qt C++ code.
25 updating could triggered with a signal from Qt C++ code.
26 \snippet ../demos/qmloscilloscope/qml/qmloscilloscope/ScopeView.qml 2
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)
167 \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY)
168 Creates a series object of \a type to the chart. For example:
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 \code
170 \code
170 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series");
171 // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes
171 scatter.markerSize = 22;
172 var myAxisX = chartView.axisX(lineSeries);
172 scatter.append(1.1, 2.0);
173 var myAxisY = chartView.axisY(lineSeries);
174 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY);
173 \endcode
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 \qmlmethod Axis ChartView::axisY(QAbstractSeries *series)
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 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name)
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 QAbstractSeries *series = 0;
569 QAbstractSeries *series = 0;
558
570
559 switch (type) {
571 switch (type) {
@@ -597,6 +609,10 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType typ
597 if (series) {
609 if (series) {
598 series->setName(name);
610 series->setName(name);
599 m_chart->addSeries(series);
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 createDefaultAxes(series);
616 createDefaultAxes(series);
601 }
617 }
602
618
@@ -122,6 +122,7 public:
122 Q_INVOKABLE QAbstractSeries *series(int index);
122 Q_INVOKABLE QAbstractSeries *series(int index);
123 Q_INVOKABLE QAbstractSeries *series(QString seriesName);
123 Q_INVOKABLE QAbstractSeries *series(QString seriesName);
124 Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = "");
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 Q_INVOKABLE void removeSeries(QAbstractSeries *series) { m_chart->removeSeries(series); }
126 Q_INVOKABLE void removeSeries(QAbstractSeries *series) { m_chart->removeSeries(series); }
126 Q_INVOKABLE void removeAllSeries() { m_chart->removeAllSeries(); }
127 Q_INVOKABLE void removeAllSeries() { m_chart->removeAllSeries(); }
127 Q_INVOKABLE void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0);
128 Q_INVOKABLE void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0);
General Comments 0
You need to be logged in to leave comments. Login now