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. ChartView with a circular buffer?

ChartView with a circular buffer?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 4 Posters 2.4k 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.
  • I Offline
    I Offline
    igor_stravinsky
    wrote on last edited by
    #1

    I've got a Quick Controls 2 chartView, in which I'd like to show the last 10 seconds of data from a running operation.

    Adding on to my line series is fairly easy:

    property int count:0
    
    onMyValueChanged: {
                    var parameterValue = value;
                   myChartLineSeries.append(count,parameterValue);
                    count++;
                }
    

    But I can't figure out how to remove the oldest element in the line series when a new one is appended. Is there any easy way to do this without copying all the values in the LineSeries?

    1 Reply Last reply
    0
    • oria66O Offline
      oria66O Offline
      oria66
      wrote on last edited by oria66
      #2

      When you want to do this sort of bounded charts, you must pay attention to:

      • How many points (x,y) you want to have in the Chart. I call it range.
      • You must take care about the sample periodo to refresh your data. In this case, we call it x
      • The axis and series data must be disengaged from the Chartview in ValueAxis and LineSeries components.

      So, in a period you must realize each refresh.

      // Here we bounded te data, removing the first element
      if(lineseries.count > range){
             lineseries.remove(0)
      }
      
      // Append new values
      lineseries.append(x, y)
      
      //we establish the new min limit of x axis to the first value of the data
      axisX.min = lineseries.at(0).x
      
      // if the data have values, we establish the last value to max Limit in X axis
      if(lineseries.count > 1){
           axisX.max = lineseries.at(lineseries.count - 1).x
      }
      

      This code works for me. Any question is welcome.

      The truth is out there

      1 Reply Last reply
      0
      • D Offline
        D Offline
        drd1988on
        wrote on last edited by
        #3

        hi
        I am also wants to use this kind of logic
        When I give idaxisX.min = idLine.at(0),it is showing Error: Cannot assign QPointF to double

        I wants to plot chart for every 1 second and the time should be the x axis label(the data is fetching from middleware )total 6 points have to show.
        Regards
        Divya

        oria66O 1 Reply Last reply
        0
        • 6thC6 Offline
          6thC6 Offline
          6thC
          wrote on last edited by
          #4

          Just a guess but if you are indeed trying to assign a QPointF to and axis.min (or max) - in your example, try: = idLine.at(0).x() (or .y() )

          If you want to manipulate the point x or y you'd modify a reference from the functions rx() and ry()

          1 Reply Last reply
          0
          • D drd1988on

            hi
            I am also wants to use this kind of logic
            When I give idaxisX.min = idLine.at(0),it is showing Error: Cannot assign QPointF to double

            I wants to plot chart for every 1 second and the time should be the x axis label(the data is fetching from middleware )total 6 points have to show.
            Regards
            Divya

            oria66O Offline
            oria66O Offline
            oria66
            wrote on last edited by
            #5

            @drd1988on Ok, you are right, it seems I forgot the x in the line

            axisX.min = lineseries.at(0).x
            

            Does this solution work for you?

            The truth is out there

            D 1 Reply Last reply
            0
            • oria66O oria66

              @drd1988on Ok, you are right, it seems I forgot the x in the line

              axisX.min = lineseries.at(0).x
              

              Does this solution work for you?

              D Offline
              D Offline
              drd1988on
              wrote on last edited by
              #6

              @oria66 yes.Thank you somuch.It worked .I have already corrected with adding.x to the line.
              Now I wants to plot bar chart like the attchment0_1548131881354_Nissan_PM2.5_Cabin_AQ_History.png
              Ho wto show thw y value near each bars and how can i give this type of colour to the bars and reduce the width of each bar?

              oria66O 1 Reply Last reply
              0
              • D drd1988on

                @oria66 yes.Thank you somuch.It worked .I have already corrected with adding.x to the line.
                Now I wants to plot bar chart like the attchment0_1548131881354_Nissan_PM2.5_Cabin_AQ_History.png
                Ho wto show thw y value near each bars and how can i give this type of colour to the bars and reduce the width of each bar?

                oria66O Offline
                oria66O Offline
                oria66
                wrote on last edited by
                #7

                @drd1988on impressive chart! Congratulations!

                I am thinking about your application, I think that level of detail you are not going to reach it only with qml. Maybe you must customize your own chart component using c++. Sincerely I do not know how to do it, but when you do it, can you post your solution? Kind regards.

                The truth is out there

                D 1 Reply Last reply
                0
                • oria66O oria66

                  @drd1988on impressive chart! Congratulations!

                  I am thinking about your application, I think that level of detail you are not going to reach it only with qml. Maybe you must customize your own chart component using c++. Sincerely I do not know how to do it, but when you do it, can you post your solution? Kind regards.

                  D Offline
                  D Offline
                  drd1988on
                  wrote on last edited by
                  #8

                  @oria66 thank you

                  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