您的位置:首页 > 其它

QCustomPlot的简单使用

2016-08-12 13:29 519 查看
简单的图标绘制可以用QCustomPlot 就一个cpp和一个.h文件包含

其他的还有QT自身的QChart,不过要QT5.X以后的版本

下载QCustomPlot  http://qcustomplot.com/index.php

最主要的类是 QCustomPlot,这是一个widget。所有的画图都是基于这个widget.

按照文章中基础的来写一个。

       QCustomPlot customPlot() ;
customPlot.resize(600,400);
// generate some data:
QVector<double> x(101), y(101); // initialize with entries 0..100
for (int i=50; i<80; ++i)
{
x[i] = i/50.0 - 1; // x goes from -1 to 1
y[i] = x[i]*x[i]; // let's plot a quadratic function
}

// create graph and assign data to it:
customPlot.addGraph();
customPlot.graph(0)->setData(x, y);
// give the axes some labels:
customPlot.xAxis->setLabel("x");
customPlot.yAxis->setLabel("y");
// set axes ranges, so we see all data:
customPlot.xAxis->setRange(-1, 1);
customPlot.yAxis->setRange(0, 1);
customPlot.replot();
customPlot.show();

实现了y=x^2的画图
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: