该库支持各种类型的图表,如曲线图、散点图、柱状图、饼图等等,而且用户还可以很容易地进行自定义设置和修改。QCustomPlot库有丰富的文档资料和示例代码,非常易于学习和使用。
一、部署QCustomplot
示例:pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的。
第一步,从QCustomPlot的官网 (https://www.qcustomplot.com/)下载最新版本的源代码,并解压到本地。
第二步,将QCustomPlot添加至自己的项目中。
在Qt Creator中打开你的项目,在工程目录中新建一个文件夹,例如 named as lib。
复制 QCustomPlot 库中的 qcustomplot.h 和 qcustomplot.cpp 文件至该文件夹中。
在Qt Creator 中添加外部库。
第三步,在项目中创建一个QCustomPlot窗口。
————————————————
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "qcustomplot.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// 创建一个QCustomPlot窗口
QCPCurve *curve = new QCPCurve(ui->customPlot->xAxis, ui->customPlot->yAxis);
ui->customPlot->addPlottable(curve);
// 设置曲线颜色
curve->setPen(QPen(Qt::blue));
// 设置坐标轴范围
ui->customPlot->xAxis->setRange(-10, 10);
ui->customPlot->yAxis->setRange(0, 100);
// 添加曲线数据并绘制
QVector<QPointF> data;
for (double x=-10; x<10; x+=0.1)
{
double y = qSin(x) * qCos(x*x);
data.append(QPointF(x, y));
}
curve->