PDA

View Full Version : Can an Axis' Labels be Redrawn?



TEAmerc
3rd November 2015, 21:44
Is there a way to redraw the labels on an axis' ticks to update the labels along it like how you can replot a QwtPlot to update the curves being drawn within?

I have a subclassed QwtScaleDraw that returns a time associated with a value v ranged from [0-PLOTUPPERBOUND] along the x-axis when it is passed label(v) and it is working but the x-axis labels are only updated after the initial setAxisScale and I haven't found out how to continue updating them after this point. I have data coming in to the plot in real time, and I'd like to have the x-axis labels also update in real time to show the time the data came in (underneath the time string the x values are static numbers of the range [0-PLOTUPPERBOUND] ). Right now if I create a new plot after the data collection has begun then I'll see the x-axis labels be updated to the current moment, but I want them to continue to update in realtime with the collected data after this point.

I've tried using the method in the cpuplot example where the axis is continuously shifted along with the data but the problem with using that method here is that it ends up breaking the qwtPlotZoomer I'm using within the plot unless I pause the plot's updating because every call to setAxisScale while updating will undo any zoom along the x-axis (the y-axis zoom remains) when new data comes in and the axes are shifted.

My subclassed QwtScaleDraw is below though it's almost exactly the same as the one from the cpuPlot example:



class TimeScaleDraw: public QwtScaleDraw
{
public:
TimeScaleDraw( QTime *base )
: baseTime( base )
{
}
virtual QwtText label( double v ) const
{
// QTime upTime = baseTime->addMSecs( static_cast<int>( v * 50 ) );
// return upTime.toString("hh:mm:ss.zzz");
return baseTime[PLOTUPPERBOUND - ((int)v % PLOTUPPERBOUND)].toString("hh:mm:ss.zzz");
}
private:
QTime *baseTime;
};

Uwe
4th November 2015, 07:19
Because of performance reasons there is a cache, that needs to be invalidated, when changing the value->text mapping: http://qwt.sourceforge.net/class_qwt_abstract_scale_draw.html#a4ed95cd23c5d77 9c1b05aa5295409aa6.

Uwe