/*----------绘图初始化设置------------*/ //绘制曲线初始化 customPlot = ui->widget; /***********************添加一条线并设置为蓝色****************************/ customPlot->addGraph(); customPlot->graph(0)->setPen(QPen(QColor(40, 110, 255))); customPlot->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, 5)); customPlot->graph(0)->rescaleValueAxis(); /***********************添加一条线并设置为橙色****************************/ customPlot->addGraph(); customPlot->graph(1)->setPen(QPen(QColor(255, 110, 40))); customPlot->graph(1)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, 5)); customPlot->graph(1)->rescaleValueAxis(); /***********************添加一条线并设置为LightGreen色****************************/ customPlot->addGraph(); customPlot->graph(2)->setPen(QPen(QColor(144,238,144))); customPlot->graph(2)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssSquare, 5)); customPlot->graph(2)->rescaleValueAxis(); /***********************添加一条线并设置为DarkRed色****************************/ customPlot->addGraph(); customPlot->graph(3)->setPen(QPen(QColor(255,69,0))); customPlot->graph(3)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDiamond, 5)); customPlot->graph(3)->rescaleValueAxis(); /***********************添加一条线并设置为OrangeRed1色****************************/ customPlot->addGraph(); customPlot->graph(4)->setPen(QPen(QColor(139,0,0))); customPlot->graph(4)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssStar, 5)); customPlot->graph(4)->rescaleValueAxis(); /***********************添加一条线并设置为Black色****************************/ customPlot->addGraph(); customPlot->graph(5)->setPen(QPen(QColor(0,0,0))); customPlot->graph(5)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssTriangle, 5)); customPlot->graph(5)->rescaleValueAxis(); /***********************添加一条线并设置为DarkGreen色****************************/ customPlot->addGraph(); customPlot->graph(6)->setPen(QPen(QColor(0,100,0))); customPlot->graph(6)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssTriangleInverted, 5)); customPlot->graph(6)->rescaleValueAxis(); /***********************添加一条线并设置为Magenta3色****************************/ customPlot->addGraph(); customPlot->graph(7)->setPen(QPen(QColor(205,0,205))); customPlot->graph(7)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssPlusSquare, 5)); customPlot->graph(7)->rescaleValueAxis(); /***********************添加一条线并设置为Magenta3色****************************/ customPlot->addGraph(); customPlot->graph(8)->setPen(QPen(QColor(205,0,205))); customPlot->graph(8)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCrossCircle, 5)); customPlot->graph(8)->rescaleValueAxis(); /***********************设置x轴是时间轴,设置y轴初始范围是0到100*********************************/ // QSharedPointer<QCPAxisTickerTime> timeTicker(new QCPAxisTickerTime); // timeTicker->setTimeFormat("%h:%m:%s.%z"); // customPlot->xAxis->setTicker(timeTicker); // customPlot->xAxis->setRange(0,curDateTime.toString("hh:mm:ss").toDouble()); // customPlot->xAxis->setRange((nowtime-10000)*0.001,nowtime*0.001); int count=xTickCount*3; qint64 now=time.toSecsSinceEpoch(); QSharedPointer<QCPAxisTicker> xTicker=customPlot->xAxis->ticker(); customPlot->xAxis->setRange(now - count,now); if(customPlot->) customPlot->axisRect()->setupFullAxesBox();//四边安装轴并显示 customPlot->yAxis->setRange(60, 70); /***********************修改成x轴/y轴终点箭头图案*********************************************/ // customPlot->xAxis->setUpperEnding(QCPLineEnding::esSpikeArrow); // customPlot->yAxis->setUpperEnding(QCPLineEnding::esSpikeArrow); /***********************显示轴标签**********************************************************/ customPlot->xAxis->setLabel("时间"); customPlot->yAxis->setLabel("距离/cm"); //移动和放缩 customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); //刻度线稍微倾斜,节省空间,参数是角度 customPlot->xAxis->setTickLabelRotation(35);//刻度线稍微倾斜,节省空间,参数是角度 QPen pen; customPlot->yAxis->setTickLengthIn(15);// 主刻度线向内延伸15 customPlot->yAxis->setSubTickLengthIn(5);//子刻度线向内延伸5 pen.setColor(Qt::blue);//子刻度线显示为蓝色 customPlot->xAxis->setSubTickPen(pen); customPlot->xAxis->setTickLengthIn(15);// 主刻度线向内延伸15 customPlot->xAxis->setSubTickLengthIn(5);//子刻度线向内延伸5 // 使左轴和底轴将其范围转移到右轴和上轴,使上下轴、左右轴范围同步 connect(customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->xAxis2, SLOT(setRange(QCPRange))); connect(customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->yAxis2, SLOT(setRange(QCPRange)));