PDA

View Full Version : setAxisScale become invalid to xTop Axis?



MickyJhon
24th January 2014, 17:36
hi, all.
i meet a problem with setAxisScale . when i use setAxisScale to set xTop axis , it can't work as i expect ,however , when i set xBottom , it works fine..

I try to change the curve by setting the xTop axis ,but the curve can't change! the code is as follow:

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->qwtPlot->setCanvasBackground( Qt::white );

ui->qwtPlot->enableAxis(QwtPlot::xBottom,false);
ui->qwtPlot->enableAxis(QwtPlot::xTop,true);

ui->qwtPlot->setAxisScale( QwtPlot::yLeft, 0.0, 10.0 );
ui->qwtPlot->setAxisScale( QwtPlot::xTop, 0.0, 10.0 );

QwtPlotCurve *curve= new QwtPlotCurve();

curve->setPen( Qt::blue );
curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );

QPolygonF points;
points << QPointF( 0.0, 4.4 ) << QPointF( 1.0, 3.0 )
<< QPointF( 2.0, 4.5 ) << QPointF( 3.0, 6.8 )
<< QPointF( 4.0, 7.9 ) << QPointF( 5.0, 7.1 );
curve->setSamples( points );

curve->attach(ui->qwtPlot);


ui->qwtPlot->resize( 600, 400 );
}


however . i can set the xBottom AXIS scale and th program works well, the key part of code is as follow:

//ui->qwtPlot->enableAxis(QwtPlot::xBottom,false);
//ui->qwtPlot->enableAxis(QwtPlot::xTop,true);

ui->qwtPlot->setAxisScale( QwtPlot::yLeft, 0.0, 10.0 );
ui->qwtPlot->setAxisScale( QwtPlot::xBottom, 0.0, 100.0 );


i want to know a way to set the xTop axis scale correctly ,can u help me?

Micky Jhon.

Cah
26th January 2014, 01:02
it can't work as i expect

Run the code below... Are the scales drawn as expected?


int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QwtPlot plot;

plot.setCanvasBackground( Qt::white );

plot.enableAxis(QwtPlot::xBottom,false);
plot.enableAxis(QwtPlot::xTop,true);

plot.setAxisScale( QwtPlot::yLeft, 0.0, 10.0 );
plot.setAxisScale( QwtPlot::xTop, 0.0, 10.0 );

QwtPlotCurve *curve= new QwtPlotCurve();

curve->setPen( Qt::blue );
curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );

QPolygonF points;
points << QPointF( 0.0, 4.4 ) << QPointF( 1.0, 3.0 )
<< QPointF( 2.0, 4.5 ) << QPointF( 3.0, 6.8 )
<< QPointF( 4.0, 7.9 ) << QPointF( 5.0, 7.1 );
curve->setSamples( points );
curve->attach(&plot);
plot.resize( 600, 400 );

plot.show();

return a.exec();
}

MickyJhon
26th January 2014, 07:31
9983, sorry, the problem is still, and the result is wrong! it looks like setAxisScale function is invalid to xTop? please help me.
Run the code below... Are the scales drawn as expected?


int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QwtPlot plot;

plot.setCanvasBackground( Qt::white );

plot.enableAxis(QwtPlot::xBottom,false);
plot.enableAxis(QwtPlot::xTop,true);

plot.setAxisScale( QwtPlot::yLeft, 0.0, 10.0 );
plot.setAxisScale( QwtPlot::xTop, 0.0, 10.0 );

QwtPlotCurve *curve= new QwtPlotCurve();

curve->setPen( Qt::blue );
curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );

QPolygonF points;
points << QPointF( 0.0, 4.4 ) << QPointF( 1.0, 3.0 )
<< QPointF( 2.0, 4.5 ) << QPointF( 3.0, 6.8 )
<< QPointF( 4.0, 7.9 ) << QPointF( 5.0, 7.1 );
curve->setSamples( points );
curve->attach(&plot);
plot.resize( 600, 400 );

plot.show();

return a.exec();
}

Uwe
26th January 2014, 09:40
The coordinate systems spanned by the 4 axes are always present - independent from the visibility of an axis. A plot item is always related to one x/y combination, different plot items on the same plot might be related to different combinations ( see the bode example, where you have 2 y axes ). In your code the curve is related to the invisible xBottom scale - because xBottom/yleft is the default setting.

The following line is missing:


curve->setXAxis( QwtPlot::xTop ):Uwe

MickyJhon
26th January 2014, 11:22
thank you very much,that's the answer!:D

The coordinate systems spanned by the 4 axes are always present - independent from the visibility of an axis. A plot item is always related to one x/y combination, different plot items on the same plot might be related to different combinations ( see the bode example, where you have 2 y axes ). In your code the curve is related to the invisible xBottom scale - because xBottom/yleft is the default setting.

The following line is missing:


curve->setXAxis( QwtPlot::xTop ):Uwe

Cah
26th January 2014, 12:30
Yes

Thanks