cannot see the curve, after attaching it to Plot
Hello,
I have created a qwtPlotCurve and attached it to a QwtPlot, but I cannot see any curve there. Please help me to get it visible.
In this function I create the curves:
Code:
void OscillationGRN::plotCurves(){
for(int j = 0; j < ListOfPlots.size(); ++j){
//create new Curve
newCurve
->setPen
(QColor(Qt
::red));
double range[] ={0,20};
double step = 0.1;
// copy the data into the curves
newCurve->setData(CurveData(range, step));
newCurve->attach(ListOfPlots[j]);
}
}
whereby
Code:
QVector<QwtPlot*> ListOfPlots;
is and CurveData is a class inherited from QwtData:
Code:
{
// The x values depend on its index and the y values
// can be calculated from the corresponding x value.
// So we don't need to store the values.
// Such an implementation is slower because every point
// has to be recalculated for every replot, but it demonstrates how
// QwtData can be used.
public:
CurveData( double rang1[2], double step)
{
rangeX[0]= rang1[0]; rangeX[1] = rang1[1];
range = (rangeX[1] - rangeX[0])/step;
if(range<0){
range = range *(-1);
}
d_size = size_t(range);
cout << "range = "<< range << " , d_size= " << d_size<< endl; // <<<<<<<< this output IS seen in console
}
{
return new CurveData(*this);
}
virtual size_t size() const
{
return d_size;
}
virtual double x(size_t i) const
{
cout << "x = " << rangeX[0] + i*((rangeX[1]- rangeX[0])/range) << endl; // <<<<<<<< this output is NOT seen in console
// here the array with x values will be produced
return rangeX[0] + i*((rangeX[1]- rangeX[0])/range);
}
virtual double y(size_t i) const
{
cout << "y = " << sin(2*3.1415926*x(i)/T)+1.0 << endl; // <<<<<<<< this output is NOT seen in console
return sin(2*3.1415926*x(i)/T)+1.0;
}
private:
size_t d_size;
double range;
double rangeX[2];
};
Re: cannot see the curve, after attaching it to Plot
by the way, if I generate x and y data by myself, it does not work, too.
Code:
void OscillationGRN::plotCurves(){
for(int j = 0; j < ListOfPlots.size(); ++j){
//create new Curve
newCurve
->setPen
(QColor(Qt
::red));
const unsigned Size=200;
double xval[Size];
double yval[Size];
double ti=0;
for(unsigned i=0; i<Size; ++i){
xval[i] = ti;
yval[i] = sin(2*3.1415926*ti/T)+1.0;
ti= ti+0.1;
}
newCurve->setRawData(xval,yval, Size);
newCurve->attach(ListOfPlots[j]);
}
}
Re: cannot see the curve, after attaching it to Plot
I'm sorry for the previous posts. I have made a big mistake forgeting to call "replot()"! :)
Code:
ListOfPlots[j]->replot();