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. Data model to update chart content

Data model to update chart content

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
pythonqmlqtchart
2 Posts 2 Posters 1.8k 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
    BobbyG
    wrote on 7 May 2019, 12:27 last edited by BobbyG 5 Jul 2019, 12:58
    #1

    I'm trying to create a data model that contains everything I need to display in my QML front end using slots and signals.

    The QML would be triggered to update and would load all it's data from the model. I want to provide all data from a Python program but a C++ solution would probably give me the information I need. I don't want to be loading chart series on the Python side, just loading up data that the QML side would extract. This way I can add extra series that one application might choose to show in a chart but another application might not. Same data model but QML picks what to use.

    The examples I have seen so far load the specific chart series for Python or C++. How can I just supply the series in the data model and get QML to extract it if required? I think the "slow method" in the following link is what I want but there is no back end code supplied so I can't see how to implement.

    QML Charts - Data from C++ and Tickmarks

    Specifically, what would you put in your main.py or main.c etc to make this work in qml:

    myLineSeries.clear()
    for(var i = 0; i < myData.dataX.length; i++) {
        myLineSeries.append(myData.dataX[i], myData.dataY[i]) // point by point append - slow
    }
    

    There seem to be lots of examples for sending across content to a listView but I can't find any for sending an array of numbers across to be read in to a chart series. Any suggestions where to look?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mammamia
      wrote on 10 May 2019, 14:21 last edited by Mammamia 5 Oct 2019, 14:55
      #2

      @BobbyG Below is the sample code which can be used to update the Chart from C++

      void PlotData::updateData(QAbstractSeries *p_series)
      {
          QVector<QPointF> pointList;
          pointList.reserve(numPts);
          for(int count = 0; count < plot_data_vector.size(); ++count)
          {
              pointList.append(x_data, y_data); // fill your plot data here
          }
      
          if(p_series)
          {
              QXYSeries *xySeries = static_cast<QXYSeries *>(p_series);
              xySeries->replace(pointList);
          }
      }
      
      void PlotData::clearSeries(QAbstractSeries *p_series)
      {
          if(p_series)
          {
              QXYSeries *xySeries = static_cast<QXYSeries *>(p_series);
              xySeries->clear();
          }
      }
      

      And from the QML you need to call this function by passing the chart view series.

      PlotData.updateData(chartView.series(1))
      

      Hope this helps...

      1 Reply Last reply
      2

      2/2

      10 May 2019, 14:21

      • Login

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