setAxisScale become invalid to xTop Axis?
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.
Re: setAxisScale become invalid to xTop Axis?
Quote:
it can't work as i expect
Run the code below... Are the scales drawn as expected?
Code:
int main(int argc, char *argv[])
{
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 );
curve->setPen( Qt::blue );
curve
->setRenderHint
( QwtPlotItem::RenderAntialiased,
true );
curve->setSamples( points );
curve->attach(&plot);
plot.resize( 600, 400 );
plot.show();
return a.exec();
}
1 Attachment(s)
Re: setAxisScale become invalid to xTop Axis?
Attachment 9983, sorry, the problem is still, and the result is wrong! it looks like setAxisScale function is invalid to xTop? please help me.
Quote:
Originally Posted by
Cah
Run the code below... Are the scales drawn as expected?
Code:
int main(int argc, char *argv[])
{
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 );
curve->setPen( Qt::blue );
curve
->setRenderHint
( QwtPlotItem::RenderAntialiased,
true );
curve->setSamples( points );
curve->attach(&plot);
plot.resize( 600, 400 );
plot.show();
return a.exec();
}
Re: setAxisScale become invalid to xTop Axis?
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:
Uwe
Re: setAxisScale become invalid to xTop Axis?
thank you very much,that's the answer!:D
Quote:
Originally Posted by
Uwe
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:
Uwe
Re: setAxisScale become invalid to xTop Axis?