Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Getting data into QML ChartView with Repeater
Forum Update on Monday, May 27th 2025

Getting data into QML ChartView with Repeater

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 1 Posters 210 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    baked_roll
    wrote on last edited by
    #1

    Hi everyone,

    I'm having problems getting data from my model which is a QList<QPointF> into the LineSeries of my ChartView in QML.

    The QML code looks like this:

    ChartView {
        Layout.fillWidth: true
        Layout.fillHeight: true
    
        legend.visible: false
        backgroundColor: "#aaa"
        backgroundRoundness: 0.0
    
        margins.top: 0
        margins.bottom: 0
        margins.left: 0
        margins.right: 0
    
        LineSeries {
            color: "#f00"
            width: 1
            useOpenGL: true
    
            axisX: ValueAxis {
                visible: false
                min: 0.0
                max: 1.0
            }
            axisY: ValueAxis {
                visible: false
                min: 0.0
                max: 1.0
            }
    
            Repeater {
                model: itemModel.chartPoints
                delegate: XYPoint {
                    x: model.x
                    y: model.y
    
                    Component.onCompleted: {
                        console.log("XYPoint completed")
                    }
                }
    
                Component.onCompleted: {
                    console.log("Repeater completed - model size: " + model.length + " example point: " + model[2])
                }
            }
            // XYPoint { x: 0.1; y: 0.5 }
            // XYPoint { x: 0.2; y: 0.4 }
            // XYPoint { x: 0.3; y: 0.7 }
        }
    }
    

    From C++ I provide this QList of QPointF for testing purposes:

    const QList<QPointF>& StockItem::chartPoints() const
    {
      static QList<QPointF> test;
      if (test.isEmpty())
      {
        test.emplace_back(QPointF(0.1, 0.5));
        test.emplace_back(QPointF(0.2, 0.4));
        test.emplace_back(QPointF(0.3, 0.7));
      }
      return test;
    }
    

    I'm getting this output from the onCompleted event of the Repeater:

    qml: Repeater completed - model size: 4 example point: QPointF(0.4, 0.3)
    

    So the model is correctly assigned and the data is available. But I don't get outputs from onCompleted events of XYPoint and the chart remains empty.
    If I uncomment this code to add points manually the lines are drawn correctly:

    XYPoint { x: 0.1; y: 0.5 }
    XYPoint { x: 0.2; y: 0.4 }
    XYPoint { x: 0.3; y: 0.7 }
    

    What am I missing here?

    I also tried using the ShapePath component with PathLine elements before since I just need a minimal data graph without legends and axes and all that stuff. But there I cannot use a Repeater at all to add points to the line.

    Thank you in advance for any help!
    Daniel

    1 Reply Last reply
    0
    • B Offline
      B Offline
      baked_roll
      wrote on last edited by
      #2

      Nevermind, I implemented my own QQuickItem which uses the QML scene graph, following this example:
      https://doc.qt.io/qt-5/qtquick-scenegraph-customgeometry-example.html

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved