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. Adding series to qml Chartview
Forum Updated to NodeBB v4.3 + New Features

Adding series to qml Chartview

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 3 Posters 3.8k Views 1 Watching
  • 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.
  • M Offline
    M Offline
    milan
    wrote on 14 Nov 2018, 17:18 last edited by
    #1

    Hello, I came across a problem. How can I add new series and remove series from existing qml Chartview from C++?
    I have data for series in C++, also I need qml Chartview as I am developing qml application. Please help. How could this be achieved

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mammamia
      wrote on 15 Nov 2018, 09:40 last edited by
      #2

      This is an abstract version of what you should do to achieve what you need.

      void PlotData::updateData(QAbstractSeries *p_series)
      {
              QVector<QPointF> pointList;
              // fill data into pointlist
              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 inside QML

      //QML
      ChartView {
      	id: chartView
      	width: 400
      	height: 300
      	antialiasing: true
      	// Plot line
      	LineSeries {
      		id: lineSeries
                      axisX: axisX
                      axisY: axisY
                      useOpenGL: true
          }
      }
      
      Button {
      	id: reload
      	onClicked: {
      		PlotData.clearSeries(chartView.series(0))  
                      PlotData.updateData(chartView.series(0))       
      	}
      }
      

      Hope it helps.

      M 1 Reply Last reply 15 Nov 2018, 16:22
      0
      • M Mammamia
        15 Nov 2018, 09:40

        This is an abstract version of what you should do to achieve what you need.

        void PlotData::updateData(QAbstractSeries *p_series)
        {
                QVector<QPointF> pointList;
                // fill data into pointlist
                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 inside QML

        //QML
        ChartView {
        	id: chartView
        	width: 400
        	height: 300
        	antialiasing: true
        	// Plot line
        	LineSeries {
        		id: lineSeries
                        axisX: axisX
                        axisY: axisY
                        useOpenGL: true
            }
        }
        
        Button {
        	id: reload
        	onClicked: {
        		PlotData.clearSeries(chartView.series(0))  
                        PlotData.updateData(chartView.series(0))       
        	}
        }
        

        Hope it helps.

        M Offline
        M Offline
        milan
        wrote on 15 Nov 2018, 16:22 last edited by milan
        #3

        @Mammamia . Thanks for your answer. I do know how to update the existing series. What I do not know is to add "new series", and to remove "existing series" from the chartview from "C++".

        D 1 Reply Last reply 16 Nov 2018, 07:50
        0
        • M milan
          15 Nov 2018, 16:22

          @Mammamia . Thanks for your answer. I do know how to update the existing series. What I do not know is to add "new series", and to remove "existing series" from the chartview from "C++".

          D Offline
          D Offline
          Diracsbracket
          wrote on 16 Nov 2018, 07:50 last edited by
          #4

          @milan
          What about the createSeries method?
          https://doc.qt.io/qt-5.11/qml-qtcharts-chartview.html#createSeries-method

          M 1 Reply Last reply 16 Nov 2018, 08:40
          0
          • D Diracsbracket
            16 Nov 2018, 07:50

            @milan
            What about the createSeries method?
            https://doc.qt.io/qt-5.11/qml-qtcharts-chartview.html#createSeries-method

            M Offline
            M Offline
            milan
            wrote on 16 Nov 2018, 08:40 last edited by
            #5

            @Diracsbracket. I know how to add series from QML, I dont know how to add from C++.

            D 1 Reply Last reply 16 Nov 2018, 09:09
            0
            • M milan
              16 Nov 2018, 08:40

              @Diracsbracket. I know how to add series from QML, I dont know how to add from C++.

              D Offline
              D Offline
              Diracsbracket
              wrote on 16 Nov 2018, 09:09 last edited by Diracsbracket
              #6

              @milan
              My bad... it seems I am turning blind and obtuse (again)...

              What about this:
              https://stackoverflow.com/questions/38467769/add-c-qabstractseries-to-qml-chartview

              Instead of instantiating the interfacing object as a QML type as in the example, you probably want to instantiate it in C++ and then pass it to the QML context. This object would emit a signal when the data is ready and the graph needs to be updated.

              In your QML you could then use a Connections {} component to connect to that signal and invoke the series-adding JS code from there.

              1 Reply Last reply
              0

              1/6

              14 Nov 2018, 17:18

              • Login

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