实时 QCustomPlot 的设置

Settings for real-time QCustomPlot

我使用 Windows 7 x64,Qt 5.6,Visual Studio 2015,QCustomPlot 1.3.2。我需要从传感器(实时)绘制温度图。我每 500 毫秒接收一次温度值 (frequency = 2 Hz)。我应该对 QCustomPlot 实例应用什么设置才能在 time_period = 10 分钟内收到最后的值? 这是更新槽的片段:

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) 的公式是什么? 官方demo包含以下值:old_items_count = 8, some_delta = 0.25.

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

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

some_delta 的值由您决定。看看 QCPAxis Class Reference.