Hello,
I am trying to plot (realtime) some lines for some sensor data without removing the older lines on the QwtPlot object from the past.
m_Gui.guiQwtPlot->setTitle(title);
m_Gui.
guiQwtPlot->setCanvasBackground
(* new QBrush(Qt
::black));
m_Gui.
guiQwtPlot->setAxisScale
(QwtPlot::yLeft,
-30.0,
30.0);
m_Gui.
guiQwtPlot->insertLegend
(new QwtLegend());
m_Gui.guiQwtPlot->legend()->setFont(fontNormal);
m_Gui.guiQwtPlot->setFont(fontNormal);
m_Gui.
guiQwtPlot->setAxisFont
(QwtPlot::yLeft, fontNormal
);
m_Gui.
guiQwtPlot->setAxisFont
(QwtPlot::xBottom, fontNormal
);
m_Gui.
guiQwtPlot->setAxisScaleDraw
(QwtPlot::xBottom,
new TimeScaleDraw
(QTime::currentTime()));
m_Gui.
guiQwtPlot->setAxisLabelRotation
(QwtPlot::xBottom,
0.0);
m_Gui.
guiQwtPlot->setAxisLabelAlignment
(QwtPlot::xBottom,Qt
::AlignLeft|Qt
::AlignBottom);
m_Gui.
guiQwtPlot->setAxisTitle
(QwtPlot::xBottom, axisTitleBottom
);
m_Gui.
guiQwtPlot->setAxisTitle
(QwtPlot::yLeft, axisTitleLeft
);
plotM->setMouseButton(Qt::NoButton);
m_Gui.guiQwtPlot->setTitle(title);
m_Gui.guiQwtPlot->setCanvasBackground(* new QBrush(Qt::black));
m_Gui.guiQwtPlot->setAxisScale(QwtPlot::yLeft, -30.0, 30.0);
m_Gui.guiQwtPlot->insertLegend(new QwtLegend());
m_Gui.guiQwtPlot->legend()->setFont(fontNormal);
m_Gui.guiQwtPlot->setFont(fontNormal);
m_Gui.guiQwtPlot->setAxisFont(QwtPlot::yLeft, fontNormal);
m_Gui.guiQwtPlot->setAxisFont(QwtPlot::xBottom, fontNormal);
m_Gui.guiQwtPlot->setAxisScaleDraw(QwtPlot::xBottom, new TimeScaleDraw(QTime::currentTime()));
m_Gui.guiQwtPlot->setAxisLabelRotation(QwtPlot::xBottom, 0.0);
m_Gui.guiQwtPlot->setAxisLabelAlignment(QwtPlot::xBottom,Qt::AlignLeft|Qt::AlignBottom);
m_Gui.guiQwtPlot->setAxisTitle(QwtPlot::xBottom, axisTitleBottom);
m_Gui.guiQwtPlot->setAxisTitle(QwtPlot::yLeft, axisTitleLeft);
QwtPlotMagnifier *plotM= new QwtPlotMagnifier(m_Gui.guiQwtPlot->canvas());
plotM->setMouseButton(Qt::NoButton);
QwtPlotPanner *plotP= new QwtPlotPanner(m_Gui.guiQwtPlot->canvas());
To copy to clipboard, switch view to plain text mode
In every 5 seconds I get new data from sensors and for each sensor I create a QwtPlotCurve then update my sensor-data with setSamples(points)
{
for(unsigned int i= 0; i< m_SensorNameList.count(); ++i)
{
m_PlotC
[m_SensorNameList.
at(i
)]->setRenderHint
(QwtPlotItem::RenderAntialiased,
true);
m_PlotC
[m_SensorNameList.
at(i
)]->setCurveAttribute
(QwtPlotCurve::Fitted);
}
m_PlotC[sensorId]->setSamples(points);
emit updatePlotSignal(m_PlotC);
}
void pcaPlotting::updateDataSlot(QString sensorId, QPolygonF points)
{
QMap<QString, QwtPlotCurve*> m_PlotC;
QStringList m_SensorNameList
for(unsigned int i= 0; i< m_SensorNameList.count(); ++i)
{
m_PlotC[m_SensorNameList.at(i)]= new QwtPlotCurve();
m_PlotC[m_SensorNameList.at(i)]->setRenderHint(QwtPlotItem::RenderAntialiased, true);
m_PlotC[m_SensorNameList.at(i)]->setCurveAttribute(QwtPlotCurve::Fitted);
}
m_PlotC[sensorId]->setSamples(points);
emit updatePlotSignal(m_PlotC);
}
To copy to clipboard, switch view to plain text mode
Finally I update my plot over signal/slot
void mainGui
::updatePlotSlot(QMap<QString,
QwtPlotCurve*> plotC
) {
for(QMap<QString,
QwtPlotCurve*>
::iterator it
= plotC.
begin(); it
!= plotC.
end();
++it
) {
plotC[it.key()]->attach(m_Gui.guiQwtPlot);
m_Gui.guiQwtPlot->replot();
}
}
void mainGui::updatePlotSlot(QMap<QString, QwtPlotCurve*> plotC)
{
for(QMap<QString, QwtPlotCurve*>::iterator it= plotC.begin(); it!= plotC.end(); ++it)
{
plotC[it.key()]->attach(m_Gui.guiQwtPlot);
m_Gui.guiQwtPlot->replot();
}
}
To copy to clipboard, switch view to plain text mode
My problem is: it plots only the data, those I got in 5 sec and then the lines are replaced with the new data after 5 sec. What should I do, so that the lines will not be replaced and increased until I stop drawing?
May be second question: The drawn data is not centered to the QwtPlot-window, it overflows in +y-axis, if the data is higher then the set boundaries setAxisScale(QwtPlot::yLeft, -30.0, 30.0); How can I draw in the center of y-axis, so that the size of the QwtPlot does not matter.
Thank you
Bookmarks