Hi Uwe,
Thanks for your kind reply.
1) You can see I want to plot temperature and pressure data against time. I have tried different code. But I either got curve1 or curve2
curve 1

curve 2
the code for curve1:
int plotSize = 100;
int timeCnt = 0;
// initialize plot data
for (int i = 0; i < plotSize; i ++)
{
x[i] = 0;
yT[i] = 0;
yP[i] = 0;
}
curveT->setRawData(x,yT,plotSize);
curveP->setRawData(x,yP,plotSize);
void cycleScrDialog::timerEvent() // timer1 generate event every 1/4 second
{
timeCnt ++;
if (timeCnt % 4 == 0)
{
x[chartCnt] = chartCnt;
yT[chartCnt] = 0.9;
yP[chartCnt] = -0.5;
ui->qwtPlot->replot();
if (chartCnt < plotSize)
chartCnt ++;
}
}
int plotSize = 100;
int timeCnt = 0;
// initialize plot data
for (int i = 0; i < plotSize; i ++)
{
x[i] = 0;
yT[i] = 0;
yP[i] = 0;
}
curveT->setRawData(x,yT,plotSize);
curveP->setRawData(x,yP,plotSize);
void cycleScrDialog::timerEvent() // timer1 generate event every 1/4 second
{
timeCnt ++;
if (timeCnt % 4 == 0)
{
x[chartCnt] = chartCnt;
yT[chartCnt] = 0.9;
yP[chartCnt] = -0.5;
ui->qwtPlot->replot();
if (chartCnt < plotSize)
chartCnt ++;
}
}
To copy to clipboard, switch view to plain text mode
code for curve 2
int plotSize = 100;
int timeCnt = 0;
// initialize plot data
for (int i = 0; i < plotSize; i ++)
{
x[i] = i; // here is the only difference
yT[i] = 0;
yP[i] = 0;
}
curveT->setRawData(x,yT,plotSize);
curveP->setRawData(x,yP,plotSize);
void cycleScrDialog::timerEvent() // timer1 generate event every 1/4 second
{
timeCnt ++;
if (timeCnt % 4 == 0)
{
x[chartCnt] = chartCnt;
yT[chartCnt] = 0.9;
yP[chartCnt] = -0.5;
ui->qwtPlot->replot();
if (chartCnt < plotSize)
chartCnt ++;
}
}
int plotSize = 100;
int timeCnt = 0;
// initialize plot data
for (int i = 0; i < plotSize; i ++)
{
x[i] = i; // here is the only difference
yT[i] = 0;
yP[i] = 0;
}
curveT->setRawData(x,yT,plotSize);
curveP->setRawData(x,yP,plotSize);
void cycleScrDialog::timerEvent() // timer1 generate event every 1/4 second
{
timeCnt ++;
if (timeCnt % 4 == 0)
{
x[chartCnt] = chartCnt;
yT[chartCnt] = 0.9;
yP[chartCnt] = -0.5;
ui->qwtPlot->replot();
if (chartCnt < plotSize)
chartCnt ++;
}
}
To copy to clipboard, switch view to plain text mode
it looks like it always links to next data (initialized data) when it plotting the last data. Can do I get rid of last plotting data, then it will look like:

2) to resize the scale, i changed my code as follow. However, no matter how do I changed the “int margin†value, I didn't see any changed of the scale. Could you please give me some advice about my code?
void cycleScrDialog::setPlot()
{
// create plot
// resize scale
layout->setAlignCanvasToScales(false);
layout->setCanvasMargin(2,-1);
// add curves
curveT
->setPen
(QPen(Qt
::red,
1));
curveT->attach(ui->qwtPlot);
curveP
->setPen
(QPen(Qt
::blue,
1));
curveP->attach(ui->qwtPlot);
// add Axis
ui
->qwtPlot
->setAxisScale
(QwtPlot::xBottom,
0,
100);
ui
->qwtPlot
->setAxisScale
(QwtPlot::yLeft,
-1,
1);
void cycleScrDialog::setPlot()
{
// create plot
QwtPlot *cyclePlot;
QwtText title("cyclePlot");
cyclePlot = new QwtPlot(title);
// resize scale
QwtPlotLayout *layout = new QwtPlotLayout;
layout->setAlignCanvasToScales(false);
layout->setCanvasMargin(2,-1);
// add curves
QwtPlotCurve *curveT = new QwtPlotCurve("Temperature");
curveT->setPen(QPen(Qt::red,1));
curveT->attach(ui->qwtPlot);
QwtPlotCurve *curveP = new QwtPlotCurve("Pressure");
curveP->setPen(QPen(Qt::blue,1));
curveP->attach(ui->qwtPlot);
// add Axis
ui->qwtPlot->setAxisScale(QwtPlot::xBottom, 0, 100);
ui->qwtPlot->setAxisFont(QwtPlot::xBottom, QFont(QString("Sans Serif"), 5, 0, false));
ui->qwtPlot->setAxisScale(QwtPlot::yLeft, -1, 1);
ui->qwtPlot->setAxisFont(QwtPlot::yLeft, QFont(QString("Sans Serif"), 5, 0, false));
To copy to clipboard, switch view to plain text mode
Thanks a lot
Bookmarks