最近需要用到这个库显示数据,需要在一个曲线图4个Y轴共用一个X轴,并且做游标,跟随鼠标移动,并且实时反馈数据到表格中。记录一下程序。
customPlot = new QCustomPlot(this);
customPlot->setBackground(QBrush(QColor(204,204,204,255)));
customPlot->setGeometry(30,50,870,350);
customPlot->installEventFilter(this);customPlot->yAxis->setRange(0,1000);customPlot->yAxis->setLabel("mm");QCPAxis *yAxisLeft1 = customPlot->axisRect()->addAxis(QCPAxis::atLeft);yAxisLeft1->setLabel("bar");yAxisLeft1->setRange(0,2500);yAxisLeft1->setTickLabels(true); QCPAxis *yAxisRight1 = customPlot->axisRect()->addAxis(QCPAxis::atRight);yAxisRight1->setLabel("m/s");yAxisRight1->setRange(0,10);QCPAxis *yAxisRight2 = new QCPAxis(customPlot->axisRect(), QCPAxis::atRight);yAxisRight2->setLabel("%");customPlot->axisRect()->addAxis(QCPAxis::atRight, yAxisRight2);yAxisRight2->setTickLabels(true);//yAxisRight2->setTickLabelRotation(90);yAxisRight2->setRange(0,100);customPlot->legend->setFillOrder(QCPLayoutGrid::foColumnsFirst);customPlot->legend->setWrap(5);customPlot->legend->setVisible(true);customPlot->plotLayout()->insertRow(0);customPlot->plotLayout()->addElement(0 , 0, customPlot->legend);customPlot->plotLayout()->setRowStretchFactor(1, 8);customPlot->legend->setBorderPen(Qt::NoPen);customPlot->legend->setBrush(Qt::NoBrush); line1 = new QCPItemStraightLine(customPlot);line1->setLayer("overlay");line1->setPen(QPen(Qt::gray, 1, Qt::DashLine));line1->setClipToAxisRect(true);line1->point1->setCoords(0, 0);line1->point2->setCoords(0, 0);line2 = new QCPItemStraightLine(customPlot);line2->setLayer("overlay");line2->setPen(QPen(Qt::gray, 1, Qt::DashLine));line2->setClipToAxisRect(true);line2->point1->setCoords(0, 0);line2->point2->setCoords(0, 0);