QCustomPlot Discussion and Comments

Hi;

I have graph and has 3 lines. there was creating before. I want to clear all data when I push the button. (These data ploting from slots.) I use two method ;

cleargraph();
clearitem();

But these code blocks delete all graph info. I want to delete only data in QCustom. How can I figure out this?

Thank you.

Like graph->clearData() ?

Make sure to replot after the delete.

Yes I m sure replot. Trow exeption there is no such a graph

Learn a bit more C++ , books or tutorials online. :)

If i understand correctly you want to hide(clear) those 3 lines so this should do it:
void QCPLayerable::setVisible ( bool on)

myGraph->setVisible(false);

You will still be able to access data from graph data container.

QCustomplot takes control of the data pointers that you pass in. if you clear the graph, it will delete the data that the pointer points to. your options are to use a different set data method(one with a deep copy), or to modify the setData method so that you have an option to not delete the data previously there, and then set an empty data for it to take control of.

I dont want to change visibility. I want to open new qcustom plot after using.


If you know so much can you give me a sample code example Isso?

If Anyone wants to answer;
I write this code and problem solved.
For more details---> https://forum.qt.io/topic/75712/qcustomplot-clear-data/8

ui->qcustom->graph(0)->data()->clear();
ui->qcustom->graph(1)->data()->clear();
ui->qcustom->graph(2)->data()->clear();
ui->qcustom->replot();

Now I see the confusion: graph->clearData() was removed in 2.0.0 and is now with the new data interface graph->data()->clear();

now its graph(0)->data().data().clear();

    
for( int g=0; g<pq_plot->graphCount(); g++ )
{
    pq_plot->graph(g)->data().data().clear();
}
pq_plot->replot();

for( int g=0; g<pq_plot->graphCount(); g++ )
{
pq_plot->graph(g)->data().data().clear();
}
pq_plot->replot();
or :
graph->data()->clear();

donot work, open task manager , the memory is still large after call the code.

The task manager is not a proper way to measure memory usage. Your operating system keeps memory allocated, even if the application has freed it, in order to speed up future allocations of that process. There's alot of literature about that on the internet.

hi, isso.
I compare to qcharts, if using replace() method ,the memory is very stable , but qcp will always increase memory. here is my code:
https://www.qcustomplot.com/index.php/support/forum/2267

Actually to clear the graph data use this, note the [->] rather than [.] after the second data():

for( int g=0; g<pq_plot->graphCount(); g++ )
{
pq_plot->graph(g)->data().data()->clear();
}
pq_plot->replot();

or you can use just the first data() but with ->

for( int g=0; g<pq_plot->graphCount(); g++ )
{
pq_plot->graph(g)->data()->clear();
}
pq_plot->replot();

The confusion is with the data(). or data()-> so the following WONT clear the data:

for( int g=0; g<pq_plot->graphCount(); g++ )
{
pq_plot->graph(g)->data().clear();
}
pq_plot->replot();