|
这样应该能满足需求,应该会有更好的方法,程序可以再优化一下,根据对应的需求
QVector<double> xVal;
QVector<double> yVal;
void GetData(double value)
{
static double maxVal = 0;
static int flag = 0;
if(value > maxVal)
{
maxVal = value;
}
if(maxVal <= 1000)
{
xVal.append(x);
yVal.append(value);
ui->customplot->graph(0)->addData(x,value);
ui->customplot->yAxis->setLabel(tr("信号(uA)"));
}
else if(maxVal > 1000)
{
if(flag == 0)//首次有大于1000的值时,对之前的值进行缩小1000倍处理,并重新添加
{
ui->customplot->graph(0)->data().data()->clear();
for(int i=0;i<xVal.size();i++)
{
yVal[i] = yVal.at(i) / 1000;
}
ui->customplot->graph(0)->addData(xVal,yVal);
flag = 1;
}
ui->customplot->graph(0)->addData(x,value/1000);
ui->customplot->yAxis->setLabel(tr("信号(mA)"));
}
}
|
|