在.pro文件中加入canvas
INCLUDEPATH += /usr/include/qwt LIBS += -L"/usr/lib/" -lqwt
头文件:app
1 #include <qapplication.h> 2 #include <qwt_plot.h> 3 #include <qwt_plot_curve.h> 4 #include <qwt_plot_grid.h> 5 #include <qwt_symbol.h> 6 #include <qwt_legend.h>
1 int main( int argc, char **argv ) 2 { 3 QApplication a( argc, argv ); ide
1 QwtPlot plot; 2 plot.setTitle( "Plot Demo" ); 3 plot.setCanvasBackground( Qt::white ); 4 plot.setAxisScale( QwtPlot::yLeft, 0.0, 10.0 ); 5 plot.insertLegend( new QwtLegend() );
新建一个QwtPlot构件,即基本的绘图表格spa
设置标题 "Plot Demo"3d
设置背景 白色 //canvas帆布code
void QwtPlot::setAxisScale ( int axisId, double min, double max, double stepSize = 0 )
Disable autoscaling and specify a fixed scale for a selected axis.
In updateAxes() the scale engine calculates a scale division from the specified parameters, that will be assigned to the scale widget. So updates of the scale widget usually happen delayed with the next replot.
Parameters
axisId min max stepSize blog
Axis index Minimum of the scale Maximum of the scale Major step size.ip
If step == 0 , the step size is calculated automatically using the maxMajor
setting.ci
对坐标尺寸的初始化,设置左边y 轴坐标的范围为0~10,坐标为非自适应.不会自动变化get
设置新的一个图例 //legend图例
1 QwtPlotGrid *grid = new QwtPlotGrid(); 2 grid->attach( &plot );
在表盘中插入网格
1 QwtPlotCurve *curve = new QwtPlotCurve(); 2 curve->setTitle( "Some Points" ); 3 curve->setPen( Qt::blue, 4 ), 4 curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
新建一个曲线
设置标题为"Some Points"
设置画笔为蓝色,宽度4
设置曲线抗锯齿
1 QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse, 2 QBrush( Qt::yellow ), QPen( Qt::red, 2 ), QSize( 8, 8 ) ); 3 curve->setSymbol( symbol );
设置符号格式,主要用来标记点
1 QPolygonF points; 2 points << QPointF( 0.0, 4.4 ) << QPointF( 1.0, 3.0 ) 3 << QPointF( 2.0, 4.5 ) << QPointF( 3.0, 6.8 ) 4 << QPointF( 4.0, 7.9 ) << QPointF( 5.0, 7.1 ); 5 curve->setSamples( points );
新建一个QPolygonF类(Qt中自带点集f->float)
其中
void QwtPlotCurve::setSamples ( QwtSeriesData < QPointF > ∗ data )
Assign a series of points
setSamples() is just a wrapper for setData() without any additional value - beside that it is easier to find for the
developer.
1 curve->attach( &plot ); 2 3 plot.resize( 600, 400 ); 4 plot.show(); 5 6 return a.exec(); 7 }
生成并画图
下面是源码方便你们复制
#include <qapplication.h> #include <qwt_plot.h> #include <qwt_plot_curve.h> #include <qwt_plot_grid.h> #include <qwt_symbol.h> #include <qwt_legend.h> int main( int argc, char **argv ) { QApplication a( argc, argv ); QwtPlot plot; plot.setTitle( "Plot Demo" ); plot.setCanvasBackground( Qt::green ); plot.setAxisScale( QwtPlot::yLeft, 0.0, 10.0 ); plot.insertLegend( new QwtLegend() ); QwtPlotGrid *grid = new QwtPlotGrid(); grid->attach( &plot ); QwtPlotCurve *curve = new QwtPlotCurve(); curve->setTitle( "Some Points" ); curve->setPen( Qt::blue, 4 ), curve->setRenderHint( QwtPlotItem::RenderAntialiased, true ); QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Diamond, QBrush( Qt::black ), QPen( Qt::red, 2 ), QSize( 8, 8 ) ); curve->setSymbol( symbol ); 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(); }