#include "qcustomplot.h"
ui.customplot->addGraph();//添加数据曲线(一个图像可以有多个数据曲线)
ui.customplot->setInteractions(QCP::iRangeDrag|QCP::iRangeZoom|QCP::iSelectPlottables);//
// graph(0);可以获取某个数据曲线(按添加先后排序)
// setData();为数据曲线关联数据
ui.customplot->graph(0)->setData(point_x, point_y);
ui.customplot->graph(0)->setName("曲线图");// 设置图例名称
// 为坐标轴添加标签
ui.customplot->xAxis->setLabel("x");
ui.customplot->yAxis->setLabel("y");
// 设置坐标轴的范围,以看到所有数据
auto max_x = std::max_element(std::begin(point_x), std::end(point_x));
auto min_x = std::min_element(std::begin(point_x), std::end(point_x));
auto max_y = std::max_element(std::begin(point_y), std::end(point_y));
auto min_y = std::min_element(std::begin(point_y), std::end(point_y));
double Max_x = *max_x;
double Min_x = *min_x;
double Max_y = *max_y;
double Min_y = *min_y;
ui.customplot->xAxis->setRange(double(Min_x), double(Max_x));
ui.customplot->yAxis->setRange(double(Min_y), double(Max_y));
ui.customplot->legend->setVisible(true); // 显示图例
// 重画图像
ui.customplot->replot();
使用了qcustomplot库,需要单独下载,网上很多,如果找不到,字数限制我贴不上,找不到的私聊我