实时QCustomPlot的设置

Settings for real-time QCustomPlot

本文关键字:设置 QCustomPlot 实时      更新时间:2023-10-16

我使用Windows 7 x64、Qt 5.6、Visual Studio 2015、QCustomPlot 1.3.2。我需要从传感器上绘制温度图(实时)。我每500毫秒接收一次温度值(frequency=2 Hz)。为了在time_period=10分钟期间收到最后一个值,我应该对QCustomPlot实例应用哪些设置?以下是续订时段的片段:

double key = QDateTime::currentDateTime().toMSecsSinceEpoch() / 1000.0;
custom_plot_->graph(0)->addData(key, value);
custom_plot_->graph(0)->removeDataBefore(old_items_count);
custom_plot_->xAxis->setRange(key + some_delta, old_items_count, Qt::AlignRight);

变量old_items_count = func1(time_period, frequency)some_delta = func2(time_period, frequency)的公式是什么?官方演示包含以下值:old_items_count = 8some_delta = 0.25

如果你的xAxis是以秒为单位的,为了保持10分钟(600秒)的恒定范围,你需要设置其范围如下:

custom_plot_->xAxis->setRange(key + some_delta, 600, Qt::AlignRight);

其中some_delta的值由您决定。查看QCPAxis类参考。