QCustomPlot Discussion and Comments

how to update graph?Return to overview

hi,i draw my graph with :

[inline]double x1, y1; 
    ui->customPlot->graph(0)->addData(x1,y1)[/inline]

how to update graph with new Series of data.that is draw graph from 0 with new data?

hi,i draw my graph with :

double x1, y1; 
    ui->customPlot->graph(0)->addData(x1,y1)

how to update graph with new Series of data.that is draw graph from 0 with new data?

First, you should take a lot at this page :

http://www.qcustomplot.com/documentation/performanceimprovement.html

This will help you to understand the QCustomPlot and the best ways to use it.

For your question, you will need to "replot" your graph to see the new data(s) added.

Use :

ui->customPlot->replot();

Be careful, do not call this function for each point added because it will slow down your app.

Hope this will help you!

I suggest use setdata() insted of adddata() if you have a new set of data each time.
Then use ui->customPlot->replot();

Refer my code here
https://github.com/bmit-pune/PDDV2_GUI/blob/master/PDD1_ver2_rev36_exp/mainwindow.cpp

thank olivier!
but my problem is not replot.i can refresh my realtime data.but when a set of new data (that will be drawn from 0 again) ,i can't remove previous data.
Piyush Ashtikar, i can't use setData because my data will be drawn realtime .
what can i do?

Have you try looping through all the rect(s) & all the graph(s) you have created and remove all the data on it !?

Somethings like :

    for(int i=0; i<axisRectCount(); i++){
        QCPAxisRect *r = axisRect(i);
        int graphOnRect = axisRect(i)->graphs().count();
        for(int j=0; j<graphOnRect; j++){
            QCPGraph *g = r->graphs().at(j);
            g->clearData();
        }
    }

Below you will find a collection of functions you are probally use.

ui->customPlot->clearGraphs();
ui->customPlot->clearItems();
ui->customPlot->clearMask();
ui->customPlot->clearPlottables();
ui->customPlot->legend->removeItem(ui->customPlot->legend->itemCount() - 1);
ui->customPlot->legend->removeItem(ui->customPlot->legend->itemCount() - 1);
ui->customPlot->legend->removeItem(ui->customPlot->legend->itemCount() - 1);
ui->customPlot->legend->removeItem(ui->customPlot->legend->itemCount() - 1);

graph()->data()->remove(key);
graph()->data().addData(key,value);

May be useful?