Use multiple series type for the same data
-
Hi all,
I am experimenting a bit with the ChartView type. I was wondering if there is a possibility to use the same data for different Series type.
For example, lets assume that the data set is
XYPoint { x: 12.2; y: 6200 } XYPoint { x: 12.4; y: 5700 } XYPoint { x: 12.6; y: 5800 } XYPoint { x: 12.8; y: 6700 }
and we want to visualize either the points (ScatterSeries), or a line (LineSeries), or a polynomial line (SplineSeries).
In the code that follows, the aforementioned Series types are combined and shown in one graph:
import QtQuick 2.11 import QtQuick.Controls 2.2 import QtQuick.Window 2.11 import QtCharts 2.0 Window { id: window visible: true width: 640 height: 480 title: qsTr("Charts") ChartView { id: myChart title: "My chart" anchors.fill: parent antialiasing: true ValueAxis { id: axisY min: 5300 max: 6800 gridVisible: true labelFormat: "%d" titleText: "Values Y" tickCount: 5 } ValueAxis { id: axisX min: 12 max: 13 gridVisible: true labelFormat: "%d" titleText: "Values X" tickCount: 3 } ScatterSeries { id: scatterSeries name: "ScatterSeries" color: "red" axisX: axisX axisY: axisY markerSize: 10 borderColor: "transparent" borderWidth: 0 XYPoint { x: 12.2; y: 6200 } XYPoint { x: 12.4; y: 5700 } XYPoint { x: 12.6; y: 5800 } XYPoint { x: 12.8; y: 6700 } } LineSeries { id: lineSeries name: "LineSeries" color: "green" axisX: axisX axisY: axisY XYPoint { x: 12.2; y: 6200 } XYPoint { x: 12.4; y: 5700 } XYPoint { x: 12.6; y: 5800 } XYPoint { x: 12.8; y: 6700 } } SplineSeries { id: mySeries name: "SplineSeries" color: "blue" width: 2 XYPoint { x: 12.2; y: 6200 } XYPoint { x: 12.4; y: 5700 } XYPoint { x: 12.6; y: 5800 } XYPoint { x: 12.8; y: 6700 } } } }
Resulting in
To me it seems redundant to copy the same data set on each Series, since they are completely the same.
The first thing that came to my mind was to declare the data set on the first series (scatterSeries on the code), and link it to the other series. Unfortunately I discovered that there is no series attribute on the several Series (LineSeries, ScatterSeries, SplineSeries, etc), but there are only functions to manually add and remove points... not quite useful.
Additionally, is there the possibility to change series type dynamically? Let's say that I don't need to simultaneously show the three types on the example. But I want to select from a combobox, whether the data is shown as ScatterSeries, or LineSeries, or SplineSerries. A solution would be to disable a <Type>Series component, so someone could just enable the desired Series component? It seems that the "enabled" property (present in Item) is not supported, since it is not derived from Item.
Thanks you in advance for any feedback!
Stam