QT之QCustomPlot的使用(一)--静态曲线

在此,我就不写QCustomPlot在哪下载什么的了。
QCustomPlot使用的不多,以我的了解,它所放置的数据都是double类型,还没有看到能有字符串类型的,如果有错误,请指出,谢谢了。

QCustomPlot* pCustomPlot=new QCustomPlot(ui->widget);//QCustomPlot的初始化,ui->widget是QCustomplot所要承载的父类
pCustomPlot->resize(300,300);//初始化坐标轴的大小,也可以用 pCustomPlot->setGeometry(1,1,300,300)
pCustomPlot->setLocale(QLocale(QLocale::Chinese, QLocale::China));//中文显示
pCustomPlot->addGraph();//添加一个数据曲线
pCustomPlot->graph(0)->setPen(QPen(QColor(255,100,0)));//设置曲线的颜色
pCustomPlot->graph(0)->setBrush(QBrush(QPixmap("./dali.png")));//设置曲线下方的背景色
pCustomPlot->graph(0)->setScatterStyle(QCpScatterStyle::ssDisc);//设置点或者线的形式
pCustomPlot->setLineStyle(QCPGraph::lsLine);//曲线的样式设置
pCustomPlot->setName("aa");//设置曲线的名字
pCustomPlot->addGraph();;//添加另外一个曲线
pCustomPlot->graph(1)->setPen(QPen(QColor(255,100,0)));//设置曲线的颜色
pCustomPlot->graph(1)->setBrush(QBrush(QPixmap("./dali.png")));//设置曲线下方的背景色
pCustomPlot->graph(1)->setScatterStyle(QCpScatterStyle::ssDisc);//设置点或者线的形式
pCustomPlot->setLineStyle(QCPGraph::lsNone);//曲线的样式设置
pCustomPlot->setName("bb");//设置曲线的名字
//是不是发现上面两个所用的方法都是一样的,在此,我想说明的是,这是建立两个曲线,第一个曲线表现的是直线,第二个曲线表现的是点。
//下面就是往曲线里面添加数据,以此来展示曲线的具体表现形式
//下面这段代码我仅仅是写出了第一条曲线的属性,第二条就省略了
QVector<double> x0(25),y0(25);//这个表示形式代表的是,第一个曲线有25个点,并且数据类型是double
for(int i=;i<25;++i)
{
   x0[i]=3*i/25.0;
   y0[i]=exp(-x0[i]*x0[i]*0.8)*(x0[i]*x0[i]+x0[i]);
}
pCustomPlot->graph(0)->setData(x0,y0);
pCustomPlot->xAxis->setVisible(true);
pCustomPlot->yAxis->setVisible(true);
pCustomPlot->xAxis->setRange(0,2.7);
pCustomPlot->yAxis->setRange(0,2.6);
pCustomPlot->xAxis->setLabel("Bottom");
pCustomPlot->yAxis->setLabel("Left");
pCustomPlot->replot();//刷新曲线

猜你喜欢

转载自blog.csdn.net/u012288722/article/details/79105940