Results 1 to 3 of 3

Thread: Set offset for first scale line in the plot

  1. #1
    Join Date
    Oct 2016
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Set offset for first scale line in the plot

    Hello All,

    I am very new to Qwt. To support our current application I am looking for the solution to my below problem.

    I have an application data plotted using qwt and it works fine. I refresh my data every 5 seconds.
    I have set lower and upper bound along with Major steps size using "setAxisScale"
    It displays the label of the Major ticks automatically, However I would like to set the scale such that it displays the time in round figure.

    Currently it displays the time randomly (at least to me!!) for example, I have given the step size as 1 Hour so it displays the label something like,

    12.01, 13.01, 14.01... etc

    How can I modify such that my xaxes adjust Major ticks to displays time in round figure like 12.00, 13.00, 14.00 ??

    Can I set the offset for first Major tick to round the time and other Major ticks fall in line based on step size?

    plot-1.jpg

    I have overloaded the label function to get the time in HH:mm format and it works fine.

    Qt Code:
    1. class TimeScaleDraw : public QwtScaleDraw
    2. {
    3. virtual QwtText label(double v) const
    4. {
    5. quint32 displytime = (int)v;
    6.  
    7. if (displytime == 0) {
    8. return QString::number(0);
    9. }
    10. else {
    11. displytime = quint32(v) - m_pd.baseSeconds;
    12. displytime *= m_pd.dataReso.width();
    13. displytime += m_pd.baseSeconds;
    14. }
    15.  
    16. QDateTime t = QDateTime::fromTime_t((int)displytime);
    17. std::string sp_temp = t.toString(format).toStdString();
    18. return t.toString(format);
    19. }
    20. };
    To copy to clipboard, switch view to plain text mode 
    *** Here, baseSeconds are the lower bound value of my graph

    However I assume that there would be some setting in the plot which will help me get the scale drawn on the hourly rounded time points.
    I am not just looking at the the changing label but label should be appropriate according to the graph position



    Thanks
    /SP
    Last edited by spanara; 6th October 2016 at 12:45.

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Set offset for first scale line in the plot

    In general there is a date/time based scale system ( QwtDateScaleEngine + QwtDateScaleDraw ), that creates useful ticks for date/time scales.
    But from your code it looks like you need a scale that displays the time elapsed since some point in time. This would be a different type of scale engine ( on my TODO list for quite some time ).

    To make it short: you also need to implement a scale engine, what mostly means to provide 2 algos for aligning a given interval and then finding the ticks.

    Uwe

  3. #3
    Join Date
    Oct 2016
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Set offset for first scale line in the plot

    Thanks for the response uwe!!

    Yes, in my case I have scaling working for me but only thing is it automatically displays the scale which I want to stream line so that my Major Ticks are drawn at round figure time like 8.00, 9.00, 10.00 based on my tick size as 60 minutes

    So, here I think if I am able to set the position for first major tick then rest will fall in line, is it possible?

    I was looking at QwtScaleDiv class but did not get much information on how I can utilize it.

    I am trying to set the QList of Major ticks (not yet achieved) to set the position of my major ticks to see if it helps me.

    Thanks
    /SP

Similar Threads

  1. Auto scale, but no plot data
    By pdm in forum Qwt
    Replies: 2
    Last Post: 20th November 2015, 16:18
  2. How to plot scale on the canvas
    By baoxuefei771 in forum Qwt
    Replies: 2
    Last Post: 29th May 2013, 20:59
  3. QwtPlot offset between Canvas and Scale
    By revellix in forum Qt Programming
    Replies: 2
    Last Post: 31st July 2011, 14:31
  4. qwp plot axis scale
    By Cal in forum Qwt
    Replies: 1
    Last Post: 11th May 2009, 18:10
  5. how to hide the scale in qwt plot
    By babu198649 in forum Qwt
    Replies: 2
    Last Post: 7th March 2008, 07:38

Tags for this Thread

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.