Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Draw a moving graph

    General and Desktop
    2
    4
    1316
    Loading More Posts
    • 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.
    • coco
      coco last edited by

      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 Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        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 ?

        coco 1 Reply Last reply Reply Quote 0
        • coco
          coco @mrjj last edited by

          @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 Reply Quote 0
          • coco
            coco last edited by

            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 Reply Quote 1
            • First post
              Last post