QCustomPlot Discussion and Comments

How to replot the graph by a buttonReturn to overview

Hello , i write a function to plot a String like "x+1",but i have tried many ways to replot the graph with no effect,here is my code:

void testWidget::QWidgetUpdate(QCustomPlot *customPlot,QString functionStr,double x_low=-1,double x_up=1,double y_low=-1,double y_up=1)
    double delta = 100/(x_up-x_low);
    QVector<double> x(101), y(101); // initialize with entries 0..100
    for (int i=0; i<101; ++i)
      x[i] = i/delta+x_low; // x goes from -1 to 1
      y[i] = Caculate_y(functionStr,x[i]);  // that's another function to caculate y
    customPlot->graph(0)->setData(x, y);
    // give the axes some labels:
    // set axes ranges, so we see all data:
    customPlot->xAxis->setRange(x_low, x_up);
    customPlot->yAxis->setRange(y_low, y_up);

tips:The function will be called when i clicked the button,and the params are not the same.

question 1:Only when i hidded customPlot at the beginng that customPlot will plot the graph.why?
question 2:I have tried customPlot->update(); customPlot->repaint(); customPlot->replot();
and also tried removeGraph() etc. All of them have no effct.

All i want to do is replot the graph,anyway,PLEASE!
Thanks for all readers.

you need to call customPlot->replot();

if you call testWidget::QWidgetUpdate in a loop / by timer, then addGraph () must be out of function.

and maybe

customPlot->xAxis->setRange(x_low, x_up);
customPlot->yAxis->setRange(y_low, y_up);

need to replace

Thanks a lot for lan and define true false
I put addGraph() out of function and add customPlot->replot() then it works
and the tip about customPlot->rescaleAxes also help me a lot
Thanks again .