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. QML Graphs using dynamic data (from C++)
Forum Updated to NodeBB v4.3 + New Features

QML Graphs using dynamic data (from C++)

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 300 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.
  • G Offline
    G Offline
    grinqt
    wrote on 4 Dec 2024, 21:39 last edited by grinqt 12 Apr 2024, 21:41
    #1

    I am trying to use QtGraphs to display an area chart of elevation data from a cycling trip. I have the data ready in C++ and am looking for a way to expose it to QML. I have been scouring the Qt docs for an explanation but every example seems to use the XYPoint classes with static data like the following:

    // Code that works but uses static data
    GraphsView {
        height: 500
        width: parent.width
        axisX: ValueAxis {
            max: 3
        }
        axisY: ValueAxis {
            max: 3
        }
        AreaSeries
        {
            color: "blue"
            upperSeries: LineSeries {
                XYPoint { x: 0.5; y: 0.5 }
                XYPoint { x: 1; y: 1 }
                XYPoint { x: 2; y: 2 }
                XYPoint { x: 2.5; y: 1.5 }
            }
        }
    }
    

    I would ideally like to do something like this instead:

    // Code that does not work but uses dynamic data instead
    GraphsView {
        height: 500
        width: parent.width
        axisX: ValueAxis {
            max: 3
        }
        axisY: ValueAxis {
            max: 3
        }
        AreaSeries
        {
            color: "blue"
            upperSeries: elevationData
        }
    }
    

    ...where elevationData is something like a QVariantMap or QStringList from C++ side. This way, if elevationData changes, the graph will change. Any ideas?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      GrecKo
      Qt Champions 2018
      wrote on 5 Dec 2024, 12:12 last edited by
      #2

      Use a XYModelMapper in combination of a QAbstractItemModel.

      1 Reply Last reply
      0

      1/2

      4 Dec 2024, 21:39

      • Login

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