QCustomPlot Discussion and Comments

removeData - Plot autofilled in the erased partReturn to overview

Hi,

I'm trying to plot real time data from 0 to N, and to go back to start when the graph reaches the right border. Then it should not erase the full data but only a couple to let plot the new data, so old one is visible when the actual updates.

My approach was:

customPlotWidget->graph(0)->removeData(key, key+2);

It's look likes to work fine, but for some reason, the replot join the actual new point with the last not erased one. I cannot figure out how to let a white space between the new data and the olda not erased data.

Any help?

Thanks in advance.

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

Hi !

Please, with Version: 2.1.0, this command is replaced by which command?

customPlotWidget->graph(1)->removeData(key-0.01, key+0.2); 

many thanks!