Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

ChartView with multiple selectable LineSeries



  • Hello everyone,

    I have a multiple series of data with 4 channels each which I want to plot using QML. A quick example of the data structure:

    "Raw Signal" :
    Channel 1 : [data]
    Channel 2 : [data]
    Channel 3 : [data]
    Channel 4 : [data]

    "Filtered Signal" :
    Channel 1 : [data]
    Channel 2 : [data]
    Channel 3 : [data]
    Channel 4 : [data]

    I want to be able to select one of the signals and either plot the 4 channels at the same time or in 4 different plots.
    The way I approached the problem was by creating a QAbstractListModel containing QAbstractTables where each table corresponds to one of the signals ("Raw Signal", "Filtered Signal").

    For plotting I wrote the following code

            StackLayout {
                id: graphsStackLayout
                Layout.fillHeight:true
                currentIndex: keysComboBox.currentIndex
                Repeater {
                    model: liveSignalsModel
                    ColumnLayout {
                        Layout.fillWidth: true
                        Layout.fillHeight: true
                        RowLayout {
                            Label {
                                Layout.preferredWidth: root.topLabelsWidth
                                text: "Channel:"
                            }
                            
                            ComboBox {
                                id: channelsComboBox
                                model: channels
                            }
                        }
                        
                        ChartView {
                            id: chartView
                            Layout.fillWidth: true
                            Layout.fillHeight: true
                            antialiasing: true
    
                            LineSeries {
                                id: line
                                name: key
                                useOpenGL: true
                                axisX: ValueAxis {
                                    min: value.xAxisData["start"]
                                    max: value.sampleCount * value.xAxisData["dx"]
                                    titleText: value.xAxisData["xLabel"] 
                                }
                                axisY: ValueAxis {
                                    min: value.minY
                                    max: value.maxY
                                    titleText: "[" + unit + "]"
                                }
                            }
    
                            HXYModelMapper {
                                id: mapper
                                model: value
                                xRow: 0
                                yRow: channelsComboBox.currentIndex + 1
                                series: line
                            }
                        }
                    }
                }
            }
    

    Where liveSignalsModel is the QAbstractListModel and keysComboBox is ComboBox that I use for selecting the signal. However this approach hoags almost all my pc resources. Creating multiple ChartViews is probably not efficient at all. Is there any other way to access the table models in the list model ? Or any better approach for my goal?

    Thank you all

    PS: I am using PySide2/QML


Log in to reply