QCustomPlot Discussion and Comments

Clearing data with 2.0.0?Return to overview

I'm trying to move to 2.0.0. What am I missing? I use data().clear() on my graph objects and data that has been added with addData() doesn't get cleared.

// data added
ui.plotWidget->graph(0)->addData(timebase, xVal);
ui.plotWidget->graph(1)->addData(timebase, yVal);

// clear data
ui.plotWidget->graph(0)->data().clear();
ui.plotWidget->graph(1)->data().clear();

Do you replot after clearing?

Oh watch out, you're clearing the pointer, not the data.

plotWidget->graph(0)->data().clear();

calls QSharedPointer method clear().
http://doc.qt.io/qt-5/qsharedpointer.html#clear

plotWidget->graph(0)->data()->clear()

is what you want,

Thanks! That was the problem. Gotta watch out for Intellisense sometimes...