Results 1 to 6 of 6

Thread: Plotting using Qwt with time values in the x-axis

  1. #1
    Join Date
    Dec 2019
    Posts
    17
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Plotting using Qwt with time values in the x-axis

    Hi,

    I have two QVectors where the y-axis has double values, but the x-axis has time values which are specified in HH::MM::SS.xxxxx, where xxxxx is in milliseconds.
    QVector<QString> timeData; //x-axis
    QVector<double> attributeData; //y-axis

    To setup a plot I have the following:
    QwtPlotCurve *curve1 = new QwtPlotCurve( "Curve 1" );

    When assigning setSamples since time is not a double value, any ideas on how to plot by time on the x axis? Of course qwt needs to be able to interpret the time so it can move along the x-axis properly. There must be a way to do it, just kind find any info on it. I tried to look it up in the documentation but no luck.

    curve1->setSamples(timeData, y-data); //time data is not a double what else can I use?

    If someone can post an example, that would great.

    Thanks in advance!

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,564
    Thanks
    255
    Thanked 728 Times in 718 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Plotting using Qwt with time values in the x-axis

    Qwt has plenty of examples of curves where the x axis labels are in time units (see here). Go look at one of those to see how the x axis data is represented and how it is mapped to x axis labels. QwtDateScaleEngine and QwtDateScaleDraw might be just the thing you are looking for.
    Last edited by d_stranz; 15th July 2020 at 15:45.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Dec 2019
    Posts
    17
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Plotting using Qwt with time values in the x-axis

    Thanks, but I was hoping to see some sort of coding example of how to implement it. Nothing fancy just how to assign a date to an array (vector/list, etc) and add it to a plot.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,564
    Thanks
    255
    Thanked 728 Times in 718 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Plotting using Qwt with time values in the x-axis

    My Qwt 6.1.3 distribution has a "playground" subdirectory with a "timescale" project in it.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Dec 2019
    Posts
    17
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Plotting using Qwt with time values in the x-axis

    Great, thanks. I'll take a look.

  6. #6
    Join Date
    Dec 2019
    Posts
    17
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Plotting using Qwt with time values in the x-axis

    I looked through the examples, but no where do I see where one can convert time since epoch (which is a double or long long int) to hh:mm::sec.zzzzzz for the x-axis. I have the value in milliseconds but how do I show it on the x-axis as readable time? Also the data is constantly updating so the x-axis time has to change with with it. This is real-time updates. There must be an example somewhere.


    Added after 1 28 minutes:


    Here is a better description of the problem. The data I get from a database is nanoseconds since 1970.
    If I use that value and print out the results such as this, I get the correct date and time:
    qDebug() << QDateTime::fromMSecsSinceEpoch(valueInNanoseconds. toLongLong()/1000000).toString();

    however when I use that same value in setSamples for the x-axis I'm off by 4 months and several hours for the date and time.

    plot = new QwtPlot();

    // add curves
    curve = new QwtPlotCurve( "Curve 1" );

    curve->attach(plot);

    scaleDraw = new QwtDateScaleDraw(Qt::UTC);
    scaleDraw->setDateFormat(QwtDate::Millisecond, "yyyy-mm-dd hh:mm:ss.zzzzzz");
    scaleDraw->setDateFormat(QwtDate::Second, "yyyy-mm-dd hh:mm:ss");
    scaleDraw->setDateFormat(QwtDate::Minute, "yyyy-mm-dd hh:mm:ss");
    scaleDraw->setDateFormat(QwtDate::Hour, "yyyy-mm-dd hh:mm:ss");
    plot->setAxisScaleDraw(QwtPlot::xBottom, scaleDraw);

    In a different method, this code fragment to plot the data, timedata is the same value as valueInNanoseconds shown above. The y-data seems to plot correctly is just the date and time does not match to what I expect.
    curve->setSamples(timeData, attributeData);
    plot->replot();


    Added after 14 minutes:


    Okay, so I fixed the problem with time being off. I should have used Qt::LocalTime which corrects the time, but not sure why the month is off. Any ideas?
    Last edited by leinad; 17th July 2020 at 17:21.

Similar Threads

  1. Replies: 5
    Last Post: 5th June 2018, 08:06
  2. Replies: 2
    Last Post: 18th October 2015, 10:17
  3. Replies: 2
    Last Post: 16th August 2011, 18:28
  4. Replies: 1
    Last Post: 2nd August 2011, 18:01
  5. real time plotting
    By gyre in forum Qwt
    Replies: 4
    Last Post: 11th December 2007, 16:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.