How to use QCustomPlot in real time
QCustomPlot
has a function setData
that takes a const variable. Can I use a way QCustomPlot
to dynamically plot a chart?
QCustomPlot
setData
the function takes constant vectors, but I need to dynamically change the values in this vector.
const QVector<double> yval(cl);
const QVector<int> xval(cl);
for (int j = 0; j<cl; j++)
yval[j] = ui->tableView->model()->data(ui->tableView->model()->index(5, j)).toDouble();
for (int j = 0; j<cl; j++)
{
xval[j] = j;
}
ui->widget->graph()->setData(xval, yval);
source to share
You can use QCPGraph :: data () . The QCustomPlot documentation states that:
Returns a pointer to the internal data store of the QCPDataMap type. You can use it to manipulate data directly, which can be more convenient and faster than using the usual setData or addData methods in certain situations.
You can manipulate data in QCustomPlot, for example:
for(int i=0; i<count; i++)
plot->graph()->data()[i] = y[i];
source to share