Continuous x-axis qwt realtime plot
I am trying to make a realtime plot and so far I got it to show a continuous sine wave, but the plot is not moving continuously on the x-axis, but more like every second it jumps one tick to the left. How can I fix this when using the QwtDateScaleDraw and QwtDateScaleEngine? I am sure it is easy, but I can not figure it out...
My code:
Code:
{
xData = new QList<double>();
yData = new QList<double>();
//Add widget to layout.
layout->addWidget(plot);
//Add curves.
curve1->setSamples(xData->toVector(), yData->toVector());
curve1->attach(plot);
//Set x-axis scaling.
QwtDateScaleDraw *qwtDateScaleDraw = new QwtDateScaleDraw (Qt::OffsetFromUTC);
QwtDateScaleEngine *qwtDateScaleEngine = new QwtDateScaleEngine(Qt::OffsetFromUTC);
qwtDateScaleDraw->setDateFormat(QwtDate::Second, "hh:mm:ss");
qwtDateScaleDraw
->setUtcOffset
(QDateTime::currentMSecsSinceEpoch() / 1000);
plot
->setAxisScaleDraw
( QwtPlot::xBottom, qwtDateScaleDraw
);
plot
->setAxisScaleEngine
( QwtPlot::xBottom, qwtDateScaleEngine
);
plot
->setAxisMaxMajor
(QwtPlot::xBottom,
0);
plot
->setAxisMaxMinor
(QwtPlot::xBottom,
10);
//Replot.
plot->replot();
//Simulated data timer.
connect(timer, SIGNAL(timeout()), this, SLOT(appendData()));
timer->start(1);
}
void MyPlot::appendData()
{
static unsigned int counter = 0;
//Add new data.
xData->append(counter);
yData->append(sin(M_PI*( (double)counter++ / 180)));
//Remove oldest data.
if (yData->size() > 1000)
{
xData->removeFirst();
yData->removeFirst();
}
//Set data.
curve1->setSamples(xData->toVector(), yData->toVector());
//Replot.
plot->replot();
}
Re: Continuous x-axis qwt realtime plot
Use QwtPlot::setAxisScale for the X axis instead of using the autoscaler.
Uwe
Re: Continuous x-axis qwt realtime plot
You are right! Thank you very much :) I did try it, but I obviously did something wrong. I still have a somewhat related problem with the timestamp label "hh:mm:ss" adjusting the x-axis every time a new x-axis label appears from the right. I guess the spacing between the major ticks changes and this looks like the x-axis is lagging a little. I would rather that the label is gradually becoming visible as the time (x-axis) increases in value. Like it fades in from the right y-axis border. Any quick tip? I have been looking at margins in the QwtDateScaleDraw and QwtDateScaleEngine, but no luck so far.