ECG 风格的实时 QCustomPlot
QCustomPlot in real time in an ECG style
我想制作一个实时图表来绘制来自我的 Arduino 的数据,我想使用 QCustomPlot 中的以下函数以 ECG 样式绘制图表(几秒钟后再次开始并替换之前的数据) :
void QCPGraph::addData(const QVector<double> &keys, const QVector<double> &values)`
从串行端口使用 keys=time
和 values=data
。
我已经有了串行数据和一个连续的图表,但我不知道如何用上面的函数修改它并制作时间向量。
你能举例说明如何调用该函数吗?
如果我没看错,你会得到一个图表,它的 xAxis
范围是恒定的。假设它被定义为 MAX_RANGE
秒,并且您希望一旦它超过 MAX_RANGE
秒,它将清除图形并从 0
秒重新开始。
如果这一切都是正确的,那么我猜你已经有了一个每 T
秒调用一次的函数来更新绘图。如果没有,请查看 this example.
假设您已经有一个每 T
秒调用一次的函数:
void MyPlot::updatePlot(int yValue)
然后只需添加一个 timeCounter
作为 class 变量,该变量将在每次调用时更新。然后添加一个 if
语句来检查它是否通过了 MAX_RANGE
。如果确实如此,则使用 clearData()
清除图表,添加新值并重置 timeCounter
。如果没有,则只需添加新值。简单示例(只需根据您的情况进行更改):
void MyPlot::updatePlot(int yValue){
this->timeCounter += T;
if (this->timeCounter >= MAX_RANGE) {
ui->customPlot->graph(0)->clearData();
ui->customPlot->graph(0)->addData(0, yValue);
this->timeCounter = 0;
}
else {
ui->customPlot->graph(0)->addData(this->timeCounter, yValue);
}
}
我想制作一个实时图表来绘制来自我的 Arduino 的数据,我想使用 QCustomPlot 中的以下函数以 ECG 样式绘制图表(几秒钟后再次开始并替换之前的数据) :
void QCPGraph::addData(const QVector<double> &keys, const QVector<double> &values)`
从串行端口使用 keys=time
和 values=data
。
我已经有了串行数据和一个连续的图表,但我不知道如何用上面的函数修改它并制作时间向量。
你能举例说明如何调用该函数吗?
如果我没看错,你会得到一个图表,它的 xAxis
范围是恒定的。假设它被定义为 MAX_RANGE
秒,并且您希望一旦它超过 MAX_RANGE
秒,它将清除图形并从 0
秒重新开始。
如果这一切都是正确的,那么我猜你已经有了一个每 T
秒调用一次的函数来更新绘图。如果没有,请查看 this example.
假设您已经有一个每 T
秒调用一次的函数:
void MyPlot::updatePlot(int yValue)
然后只需添加一个 timeCounter
作为 class 变量,该变量将在每次调用时更新。然后添加一个 if
语句来检查它是否通过了 MAX_RANGE
。如果确实如此,则使用 clearData()
清除图表,添加新值并重置 timeCounter
。如果没有,则只需添加新值。简单示例(只需根据您的情况进行更改):
void MyPlot::updatePlot(int yValue){
this->timeCounter += T;
if (this->timeCounter >= MAX_RANGE) {
ui->customPlot->graph(0)->clearData();
ui->customPlot->graph(0)->addData(0, yValue);
this->timeCounter = 0;
}
else {
ui->customPlot->graph(0)->addData(this->timeCounter, yValue);
}
}