So far, the best approach was to have 2 simultaneous graphs: one with the actual data and the other one with the old data.
The new one is adding new data from 0 to right border and the other one deletes the old graph from 0 to right border but with and offset form actual key and with a specified size.
Some code to illustrate:
// To retart the graph
if (key>=TIMER_SCALE_S){
key=0;
graphInterchange=!graphInterchange;
}
// Add data to the graphs. Select the secuence of graphs
// (one adding and other erasing data).
if(graphInterchange){
// Remove data between old and new data
customPlotWidget->graph(1)->removeData(key-0.01, key+0.2);
// Add data to graph
customPlotWidget->graph(0)->addData(key, graphData);
// Add data to dots graph in the top of the other graph
customPlotWidget->graph(3)->clearData();
customPlotWidget->graph(3)->addData(key, graphData);
// Rescale y axis to fit the current data:
customPlotWidget->graph(0)->rescaleValueAxis();
customPlotWidget->graph(1)->rescaleValueAxis(true);
}
else{
// Remove data between old and new data
customPlotWidget->graph(0)->removeData(key-0.01, key+0.2);
// Add data to graph
customPlotWidget->graph(1)->addData(key, graphData);
// Add data to dots graph in the top of the other graph
customPlotWidget->graph(3)->clearData();
customPlotWidget->graph(3)->addData(key, graphData);
// Rescale y axis to fit the current data:
customPlotWidget->graph(0)->rescaleValueAxis();
customPlotWidget->graph(1)->rescaleValueAxis(true);
}
// Set x range
customPlotWidget->xAxis->setRange(0, TIMER_SCALE_S, Qt::AlignLeft);
// Replot
customPlotWidget->replot();
// Increment the sample time - Must be the same as the timeout to call
// this function.
key+=TIMER_MS*0.001;
Regards,
Santiago