PDA

View Full Version : Scale change for seconds / milliseconds



Nijaguna
16th January 2017, 07:13
Hello All,

I have just started with the Qt and Qwt.

The tool I am developing, the X axis is represented by time - seconds and milliseconds and Y axis the values corresponding to the time. Tool also has a combo box which zooms the chart. The entries in combo range from 10 seconds down to 1 millisecond. (10sec, 5sec, 2sec, 1sec, 500msec, 250 msec, 100msec, 50msec, 10msec, 5 msec and 1msec). The requirement is when the user selects the time in seconds in combo box, the X axis should show "seconds" as title and when milliseconds should show "milliseconds". I am able to set the title correctly, as I check the index in combo, to toggle between "seconds" and "milliseconds".

I am using SetAxisScale method. When user selects "10sec" I set min and max for SetAxisScale diving by 1000 but when user has "10msec" in combo I call SetAxisScale but the charts do not understand whether 10 is sec or msec and is wrong.

Summary:
=======

User selects "10sec", title is "seconds". Ticks should show 10, 20, 30... I call SetAxisScale with data divided by 1000.
User selects "10msec", title is "milliseconds". Ticks should again show 10, 20, 30...


How do I set the ticks correctly and the chart data correctly?

Regards,
Nijaguna

Uwe
16th January 2017, 07:51
Assuming your data is in ms:


class YourScaleDraw: public QwtScaleDraw
{
public:
....

virtual QwtText label( double value ) const override
{
if ( m_mode == Seconds )
value /= 1000.0;

return QwtScaleDraw::label( value );
}

private:
Mode m_mode;
};

plot->setAxisScaleDraw( ..., new YourScaleDraw(...) );Uwe

Nijaguna
16th January 2017, 12:55
Thanks a lot ! Able to show the chart correctly.