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);
暂时就写那么多。






  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值