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!

QCPBars *newbars=new QCPBars(ui->widget->xAxis , ui->widget->yAxis);

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:

makePlot(); // my custom function