我使用 Windows 7 x64、Qt 5.6、Visual Studio 2015、QCustomPlot 1.3.2。我需要从传感器(实时)绘制温度图。我每 500 毫秒接收一次温度值(频率
= 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)
的公式是什么?
官方演示包含以下值: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 .
关于c++ - 实时 QCustomPlot 的设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36650092/