QCustomPlot 去掉x=0坐标轴的实线

之前绘制曲线,x=0/y=0坐标轴的实线感觉太多余了

plot->xAxis->grid()->setZeroLinePen(Qt::NoPen);
plot->yAxis->grid()->setZeroLinePen(Qt::NoPen);

在这里插入图片描述
在这里插入图片描述

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
QCustomPlot是一个强大的C++图形库,可用于创建动态曲线图。如果您想要绘制X轴坐标为时间的动态曲线,可以按照以下步骤操作: 1.创建一个QCustomPlot对象并设置其X轴为时间类型: ```c++ QCustomPlot *customPlot = new QCustomPlot(); customPlot->xAxis->setType(QCPAxis::atDateTime); ``` 2.创建一个QCPGraph对象并将其添加到QCustomPlot中: ```c++ QCPGraph *graph = customPlot->addGraph(); ``` 3.在每个时间点上添加数据。假设您有一个名为“data”的QVector对象,其中包含时间和值的数据: ```c++ for (int i=0; i<data.size(); ++i) { double time = QDateTime::fromString(data[i].time, "yyyy-MM-dd hh:mm:ss.zzz").toMSecsSinceEpoch(); double value = data[i].value; graph->addData(time, value); } ``` 在这里,我们将时间转换为毫秒级别,因为QCustomPlot使用毫秒作为时间单位。 4.为X轴设置时间格式。您可以使用QCustomPlot的时间格式化字符串来设置您想要的日期和时间格式: ```c++ customPlot->xAxis->setDateTimeFormat("hh:mm:ss"); ``` 5.启用自适应X轴范围,以便在动态添加数据时自动扩展X轴范围: ```c++ customPlot->xAxis->setRange(QCPAxisTickerDateTime::dateTimeToKey(QDateTime::currentDateTime().addSecs(-60)), QCPAxisTickerDateTime::dateTimeToKey(QDateTime::currentDateTime())); customPlot->xAxis->setAutoTickStep(false); customPlot->xAxis->setTickStep(10); ``` 在这里,我们将X轴范围设置为最近60秒,然后启用手动刻度步长,并将其设置为10秒。 6.最后,您需要调用replot()函数来绘制动态曲线: ```c++ customPlot->replot(); ``` 完整代码示例: ```c++ QCustomPlot *customPlot = new QCustomPlot(); customPlot->xAxis->setType(QCPAxis::atDateTime); QCPGraph *graph = customPlot->addGraph(); for (int i=0; i<data.size(); ++i) { double time = QDateTime::fromString(data[i].time, "yyyy-MM-dd hh:mm:ss.zzz").toMSecsSinceEpoch(); double value = data[i].value; graph->addData(time, value); } customPlot->xAxis->setDateTimeFormat("hh:mm:ss"); customPlot->xAxis->setRange(QCPAxisTickerDateTime::dateTimeToKey(QDateTime::currentDateTime().addSecs(-60)), QCPAxisTickerDateTime::dateTimeToKey(QDateTime::currentDateTime())); customPlot->xAxis->setAutoTickStep(false); customPlot->xAxis->setTickStep(10); customPlot->replot(); ``` 希望这可以帮助您创建X轴坐标为时间的动态曲线!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值