
Originally Posted by
Uwe
Not surprising, because in your code is only one curve. The second setData call changes the points of the curve, but doesn't create a second one.
Instead you need to attach 2 different QwtPlotCurve objects - one for each array.
Uwe
Thanks, I think the problem is solved, the changed code:
Plot::Plot()
{
setTitle("A Simple QwtPlot Demonstration");
// Set axis titles
setAxisTitle(xBottom, "x -->");
setAxisTitle(yLeft, "y -->");
// Insert new curves
for(int j=0; j<2; j++)
{
#if QT_VERSION >= 0x040000
cSin
[j
]->setRenderHint
(QwtPlotItem::RenderAntialiased);
#endif
cSin
[j
]->setPen
(QPen(Qt
::red));
cSin[j]->attach(this);
}
const int nPoints = 100;
double x[2][nPoints], y[2][nPoints];
for(int j=0; j<2; j++)
{
for(int i=0; i<nPoints; i++)
{
x[j][i] = -3.14 + i*(j+2)*3.14/(nPoints-1);
y[j][i] = sin((j+1)*x[j][i]);
}
}
// Create 2d array data
for(int j=0; j<2; j++)
cSin[j]->setData(x[j],y[j],nPoints);
}
Plot::Plot()
{
setTitle("A Simple QwtPlot Demonstration");
insertLegend(new QwtLegend(), QwtPlot::RightLegend);
// Set axis titles
setAxisTitle(xBottom, "x -->");
setAxisTitle(yLeft, "y -->");
// Insert new curves
QwtPlotCurve **cSin;
cSin= new QwtPlotCurve* [2]; //("y = sin(x)");
for(int j=0; j<2; j++)
{
cSin[j]=new QwtPlotCurve;
#if QT_VERSION >= 0x040000
cSin[j]->setRenderHint(QwtPlotItem::RenderAntialiased);
#endif
cSin[j]->setPen(QPen(Qt::red));
cSin[j]->attach(this);
}
const int nPoints = 100;
double x[2][nPoints], y[2][nPoints];
for(int j=0; j<2; j++)
{
for(int i=0; i<nPoints; i++)
{
x[j][i] = -3.14 + i*(j+2)*3.14/(nPoints-1);
y[j][i] = sin((j+1)*x[j][i]);
}
}
// Create 2d array data
for(int j=0; j<2; j++)
cSin[j]->setData(x[j],y[j],nPoints);
}
To copy to clipboard, switch view to plain text mode
Bookmarks