cpp
// QCustomPlot *customPlot;
const QVector<double> x = {0, 1, 2, 3, 4, 5};
const QVector<double> y = {1, 1, 2, 2, 4, 4};
customPlot = ui->ctp;
customPlot->setOpenGl(true);
customPlot->addGraph();
customPlot->xAxis->setRange(0, 5);
customPlot->yAxis->setRange(0, 5);
customPlot->xAxis2->setRange(0, 5);
customPlot->yAxis2->setRange(0, 5);
customPlot->xAxis2->setVisible(true);
customPlot->yAxis2->setVisible(true);
customPlot->graph(0)->setData(x, y);
customPlot->legend->setVisible(false);
customPlot->graph(0)->setLineStyle(QCPGraph::LineStyle::lsLine); // 设置线性
// customPlot->graph(0)->setName("TEST");
// customPlot->xAxis->setLabel("x");
// customPlot->yAxis->setLabel("y");
// customPlot->replot();
// customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
customPlot->axisRect(0)->setRangeZoomFactor(0.9, 0.9); // x方向为1.2
customPlot->setInteractions(QCP::iRangeZoom);