QCustomPlot Discussion and Comments

How to delete QCPBars from qcustomplot?Return to overview

Hello! I am working with bar chart and everythink is ok, but when I open form for second time there are appears 2 charts,when third-3 and etc. How to avoid it? Thank you!
http://s019.radikal.ru/i642/1405/14/208c20ec7b88.png
http://s019.radikal.ru/i635/1405/ab/70cfdd555395.png

QCPBars *newbars=new QCPBars(ui->widget->xAxis , ui->widget->yAxis);
xData<<xd;
yd++;
yData<<yd;
newbars->setData(xData,yData);
ui->widget->replot();

I have a tip, zero the variables before the form is closed.

If you open the form a second time and call your code at every form-opening, of course it will add new bars at every opening. The solution is not to remove the superfluous bars, but not adding them in the first place. So only call that code above once and then change the data (if necessary on successive form-openings) via accessing the existing bars plottable. You could for example save the "newbars" pointer as a private member of the window class.

If you really want to remove a plottable, use QCustomPlot::removePlottable, or even QCustomPlot::clearPlottables to remove all.

Man u really helped me :)

thx manu, that helped me too!

Thank you. Saved my life with a project using bar charts. Additionally, I used:

ui->my_plot->clearPlottables();
ui->my_plot->replot();
makePlot(); // my custom function