QCustomplot用法小结

因为qcustomplot提供了文档,在这里就列出几个比较常用的接口。

1.设置缩放,拖拽,设置图表的分类图标显示位置

 m_customplot->setInteractions( QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes);
 m_customplot->axisRect()->insetLayout()->setInsetAlignment(0,Qt::AlignTop | Qt::AlignRight);

2.如下图依次是,设置左侧纵坐标的名字,显示在y轴上,颜色设置,范围设置,是否需要显示每个mark点的值。

 m_customplot->yAxis->setLabel("AAA");
 m_customplot->yAxis->setLabelColor(QColor(BBB));
 m_customplot->yAxis->setRange(0, 100);
 m_customplot->yAxis2->setTickLabels(true);

3.将第一条插入图表的曲线加入数据,然后刷新。。

 m_customplot->graph(0)->addData(Index, 888);
 
    
 m_customplot->replot();

4.缩放或者拖拽特定的轴。有多个重载函数可以查看文档。

 m_customplot->axisRect()->setRangeZoomAxes(0, m_customplot->yAxis);
 m_customplot->axisRect()->setRangeZoom(Qt::Vertical);
 m_customplot->axisRect()->setRangeDragAxes(0, m_customplot->yAxis2);
 m_customplot->axisRect()->setRangeDrag(Qt::Vertical);

5.清除数据

 m_customplot->graph(0)->data()->clear();
 m_customplot->graph(1)->data()->clear();

6.坐标转换,求出点击的x对应的y值

 m_customplot->xAxis->pixelToCoord(event->pos().x())
 m_customplot->graph(0)->dataCount()
 double y1 = m_data->m_customplot->graph(0)->data()->at(x)->value

7.横坐标相同时候,在两个曲线之间在纵向上连起来,用来作比较,更加直观

 double pixX = m_customplot->xAxis->coordToPixel(x);
 plotLine->point_1->setPixelPosition(QPointF(pixX, 0));
 plotLine->point_2->setPixelPosition(QPointF(pixX, 1));
 plotLine->setVisible(true);

 graphTracer0->setGraphKey(x);
 graphTracer0->setVisible(true);
 graphTracer1->setGraphKey(x);
 graphTracer1->setVisible(true);
暂时就写那么多。



 
    
 
    
 
   

你可能感兴趣的:(Qt)