QwtPlotcurve multiple curves
Hi,
I would like to plot multiple curves on one qwtplot object.
Code:
QwtPointSeriesData* myData = new QwtPointSeriesData;
QVector<QPointF>* samples = new QVector<QPointF>;
samples
->push_back
(QPointF(time
->at
(0), samplesPerUser
[0]));
//creating histogram
for (int i=1; i<30; i++) {
samples
->push_back
(QPointF((time
->at
(i
) + time
->at
(i
+1)) / 2, samplesPerUser
[i
]));
samples
->push_back
(QPointF((time
->at
(i
) + time
->at
(i
+1)) / 2, samplesPerUser
[i
+1]));
}
samples
->push_back
(QPointF(time
->at
(30), samplesPerUser
[30]));
myData->setSamples(*samples);
mycurve->setData(myData);
mycurve->attach(plot);
QwtPointSeriesData* myData2 = new QwtPointSeriesData;
QVector<QPointF>* samples2 = new QVector<QPointF>;
samples
->push_back
(QPointF(time
->at
(0), samplesPerUser2
[0]));
//creating histogram
for (int i=1; i<30; i++) {
samples2
->push_back
(QPointF((time
->at
(i
) + time
->at
(i
+1)) / 2, samplesPerUser2
[i
]));
samples2
->push_back
(QPointF((time
->at
(i
) + time
->at
(i
+1)) / 2, samplesPerUser2
[i
+1]));
}
samples
->push_back
(QPointF(time
->at
(30), samplesPerUser2
[30]));
myData->setSamples(*samples2);
mycurve->setData(myData2);
//making the second curve red
mycurve2
->setPen
(QPen(Qt
::red));
mycurve2->attach(plot);
The problem is that I can see only the second curve, not the first one. I'm not sure whether creating 2 QwtPlotCurve object and attaching them to the plot is a right approach.
Re: QwtPlotcurve multiple curves
Avoid Copy & Paste, that's where you'll make most mistakes.
In line #29 by mistake you're setting your second data set on first curve.
And creating two curves and attaching them to the plot is the right approach :)
Re: QwtPlotcurve multiple curves
but how to create two dynamic curves in one plot canvas with different types of data?
for example, the data for the first curve may be sampled from the ADC device,and the data for the second curve is from mathematical function like square wave function?
Re: QwtPlotcurve multiple curves
All of the code that you provided looks correct to me, except line 29 (which has already been pointed out to you). This line should be
Code:
mycurve2->setData(myData2);
(Note: mycurve2, not mycurve).
You probably have some major memory leaks, because I think you are making new QVector instances when you should simply create them on the stack. But get the curves displayed first, then fix the memory problems.
Re: QwtPlotcurve multiple curves
Thanks all. It works now.