Re: Real time data plotting using Qwt
Hello every one, i am working on a plotting software where i have to plot some temperature data. I wrote the program but i am missing something i guess.. I don't have the temperature data plotted..
Code:
#include "mux_selection.h"
mux_selection
::mux_selection(QWidget *parent
) , m_curve(0)
, curve(0)
{
minX =0;
maxX =60;
//enable the x and y axis lines
grid->enableX(true);
grid->enableY(true);
timerdrawplot
= new QTimer(this);
//set the X and Y division and scale to that of the channels
grid
->setXDiv
(*(myPlot
->axisScaleDiv
(QwtPlot::xBottom)));
grid
->setYDiv
(*(myPlot
->axisScaleDiv
(QwtPlot::yLeft)));
grid->attach(myPlot);
myPlot->setCanvasBackground("lightyellow");
myPlot->setTitle("Data Receiver");
myPlot
->setAxisTitle
(QwtPlot::xBottom,
"Time in Seconds");
myPlot
->setAxisScale
(QwtPlot::xBottom,
0,
60);
myPlot
->setAxisTitle
(QwtPlot::yLeft,
"<FONT color=#0000ff face=Arial size=4><B> Temperature in C° </FONT>");
myPlot
->setAxisScale
(QwtPlot::yLeft,
-200,
+200);
myPlot->setAutoReplot(true);
}
i am calling the plot function when i click the plot button using a timer every 1000 mili sec. right now i am retrieving one channel data from the db and trying to display it.
Code:
void mux_selection::plot()
{
m_vx.clear(); // QVector<double> m_vx,m_vy;
m_vy.clear();
QSqlQuery q
("select "+ colNames
+" from tempdata where rowid = " + QString::number(rowcnt
));
// colNames = channel1;
while(q.next())
{
m_vx.push_back(q.value(0).toDouble());
m_vy.push_back(q.value(1).toDouble());
}
if(m_vx.count()!= 0)
{
rowcnt++;
}
qDebug()<<m_vy<<m_vx<<rowcnt;
if (!m_curve)
{
m_curve
->setPen
(QPen(Qt
::black,
2,t
::SolidLine));
m_curve->setData(m_vx.data(), m_vy.data(), m_vx.count());
}
myPlot
->setAxisScale
( QwtPlot::xBottom, minX , maxX
);
myPlot->replot();
}
i am able to figure out where i am going wrong... :confused:
Thank you
Added after 1 55 minutes:
hello is there anything wrong in the program. . ? pls help me out not able to know where i am going wrong.
thanks so much
Re: Real time data plotting using Qwt
somebody please help me out.. not able to know where i am going wrong.. I have been trying different other things but not able to plot the data from the data base. :(
regards
Re: Real time data plotting using Qwt
have a look at this snippet:
Code:
if (!m_curve)
{
m_curve
->setPen
(QPen(Qt
::black,
2,t
::SolidLine));
m_curve->setData(m_vx.data(), m_vy.data(), m_vx.count());
}
m_curve is a member of your class, you initialize it with 0. The first time "plot()" gets called, you assign a "new QwtPlotCurve" to m_curve. What happens when "plot()" gets called next time?
Felix
Re: Real time data plotting using Qwt
Also use autoscaling for the moment to avoid, that the values are somewhere outside the visible area. It might be a good idea to check the samples, that are assigned to the curve.
Uwe
Re: Real time data plotting using Qwt
Hello thank you for the reply.. I did check on the samples if the data is present the data is present the Time Interval and the channel data is there.. But i still don have the curve plotted.
Code:
qDebug()<<m_vx<<m_vy<<colNames;
if (m_vx.count() <= 0) // no data no curve.
return;
m_lastTime = (int)m_vx[m_vx.count() + 1];
if (!m_curve)
{
m_curve
->setPen
(QPen(Qt
::red));
m_curve->setData(m_vx.data(), m_vy.data(), m_vx.count());
}
m_curve->attach(myPlot);
m_curve
->setPen
(QPen(Qt
::red));
m_curve->setData(m_vx.data(), m_vy.data(), m_vx.count());
}
but this does't work .. as FelixB told i did not plot the data after the initial call so i have set the pen and Data after it. But still i don have a curve plotted.
regards
Re: Real time data plotting using Qwt
hey i solved the problem.. :) Thanks for the suggestions.
Re: Real time data plotting using Qwt
So how did you fix the problem?
Re: Real time data plotting using Qwt
hey would you please post your final solution please............
I badly need it
Re: Real time data plotting using Qwt
Notice that in the original code, the curve was never "attached" to the plot. So even though the curve was created correctly, the plot was never told about it, so of course it never is drawn.
In the revised code (March 16), attach is called, but the code is still incorrect: attach is called every time the plot() method executes. It only needs to be called once, in the section of code that creates the curve ( if ( !m_curve )... ).
Likewise, the pen color never changes, so it is not necessary to set the pen every time plot() is executed. The only call needed each time plot() is executed is to update the data pointers.
And in this particular case, since it looks like the mux_selection class is keeping its own copy of the data (m_vx, m_vy), the setRawData() method should be used instead of setData(), since setData will make another copy of the data. If the data arrays are large, this will cause performance problems because of all the extra memory allocation and copying in the curve.