Important: Please read the Qt Code of Conduct -

QML, create LineSeries at runtime

  • My goal is to have a QML ChartView with a variable number of LineSeries added to it during runtime. It is unknown how many LineSeries will need to be added until a user selects and loads a file with the data in it.

    I tried to create all of the LineSeries inside a Repeater, with no luck. I suspect it's because ChartView doesn't know what to do with a bunch of Item's. It's not possible to have the Repeater create LineSeries directly since a Repeater doesn't work on QObject's:

    ChartView {
        Repeater {
            model: numberOfColumnsInModel / 2
            delegate: Item {
                LineSeries {
                    id: lineSeries
                    axisX: xAxis
                    axisY: yAxis
                    VXYModelMapper {
                        id: modelMapper
                        model: lineChart.model //Reimplemented QAbstractTableModel
                        xColumn: index * 2
                        yColumn: index * 2 + 1
                    onHovered: {
                        console.log("Do something...");

    In the examples I see online, each LineSeries is hard-coded--once for each line in the ChartView--and not useful to me.

Log in to reply