Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Draw a moving graph

Draw a moving graph

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.6k 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.
  • cocoC Offline
    cocoC Offline
    coco
    wrote on last edited by
    #1

    Hello, I would like to draw a moving graph where the graph changes every second for a day period of time.

    I calculate the data to plot the graph from some mathematics equations and keep them in a vector. One parameter used for calculation is time which is extracted from computer time. So for 1 sec, I get something like 300 points.

    One solution I can think of is I collect the data into multidimensional vector where row is time and column is data. Then read each row every second and use paintevent to draw the graph.

    Are there any better methods?

    Or how can I create multidimentional vector? I can get one vector, no problem but how can I get them pile up.

    Until now I can draw the graph. I have a problem with updating them each second.

    Thank you.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome
      What kind of graph is that?
      Have you considered using a plot widget ?
      like
      http://www.qcustomplot.com/
      http://qwt.sourceforge.net/
      to get zooming etc for free?

      anyway.
      I wonder instead of multi vector then a data class?

      class GData {
      std:.vector<double> data;
      };

      std:.vector<GData> GraphsUpdates;

      Then you could store more.

      But im not 100% sure why you need to pile them up ?
      If you have 1 sec to draw the points, should be fine or ?

      cocoC 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi and welcome
        What kind of graph is that?
        Have you considered using a plot widget ?
        like
        http://www.qcustomplot.com/
        http://qwt.sourceforge.net/
        to get zooming etc for free?

        anyway.
        I wonder instead of multi vector then a data class?

        class GData {
        std:.vector<double> data;
        };

        std:.vector<GData> GraphsUpdates;

        Then you could store more.

        But im not 100% sure why you need to pile them up ?
        If you have 1 sec to draw the points, should be fine or ?

        cocoC Offline
        cocoC Offline
        coco
        wrote on last edited by
        #3

        @mrjj It's a day and night terminator map. I have an equation to calculate the graph and can plot it on a cylindrical map projection of the world. The graph has 360 points width. And since the terminator depends on hours of the day and days of the year, I would like to update it every second (though we won't see much different from the previous second :)).

        Thank you for your suggestion. I will take a look on those plot widgets and class.

        But im not 100% sure why you need to pile them up ?

        I store my 360 points xy into QVector and use QPainter to draw it. I was thinking of triggering every row each second so that the graph would update as said.

        1 Reply Last reply
        0
        • cocoC Offline
          cocoC Offline
          coco
          wrote on last edited by
          #4

          So I figured out how to do it.
          First I calculate the graph using the date and time provided by QDateTime. The 360 points xy are kept in vectorA. I copy vectorA into vectorB and use vectorB to draw the graph using QPainter and QPainterPath to fill the upper area.

          Thank you.

          1 Reply Last reply
          1

          • Login

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