PDA

View Full Version : [SOLVED]QLineSeries extremely slow



NicolasCasime
23rd May 2018, 14:49
Hi everybody!

Im having some trouble using QtCharts.

My application needs to plot some linear graphs. I have the data contained on an Array.
I need to plot between 100 and 20000 points or so.


On my .h






QChart *Chart;
QLineSeries *Serie;
QChartView *View;





How I Initialize everything



void Initialize(void)
{
Serie=new QLineSeries();
Chart=new QChart();
Chart->legend()->hide();
Chart->addSeries(Serie);
Chart->createDefaultAxes();
View= new QChartView(Chart);
View->setRenderHint(QPainter::Antialiasing);
}



Now lets assume I want to plot 10000 points (I dont care about the value)




void Plot(void)
{
//------------Reset-------------------
Serie->clear();
//---------------------------------------

for(long int i=0;i<10000;i++)
{
QApplication::processEvents();
Serie->append(i,i+10);//Right now I dont care about the value
}
Chart->removeSeries(Serie);
Chart->addSeries(Serie);
}


That "for" loops takes like 20 seconds to complete. Freezing all of my program.
Im not doing anything weird, just calling the append method of a QLineSeries.

Am i doing something wrong?
Is there a way to append 10K points and not having to wait so much?


The final Chart looks exactly as i want it to look. Its just that I wait that much each time I need to plot some data

Any ideas?

Thanks in advance

Added after 21 minutes:

UPDATE:

I have read that you can call the setUseOpenGL() method of the LineSeries to make it faster.
On my example, it has the opposite effect. If i activate the OpenGL, the for will take even longer to finish.

Added after 14 minutes:

Another Update:

In order to understand why it takes So long to plot. I placed a progressbar which increases as the for loop advances.
The results where quite strange.

The time it takes to complete that for is not Linear!
What do i mean?

The beggining of the for is done extremely fast. As "i" advences, each time the append operation takes more time.

Lets make a basic example. If on my computer takes 20 seconds to complete that for sequence...
After 5 seconds: 50 % of the Graph plotted
After 10 seconds: 80% of the Graph plotted
After 15 seconds:n 95% of the Graph plotted

Why does this happen?
The insertion time of a list is always the same, It doesnt matter how much nodes that list has...

Ginsengelf
23rd May 2018, 15:59
Hi, maybe it helps to add the QLineSeries to the QChart after you have filled it? Also I think calling processEvents() after each value is a bit much.

Ginsengelf

NicolasCasime
23rd May 2018, 16:12
Creating the series first, and adding it to the Chart after all of the appends solved the problem

Each append if the seires is already on the QChart triggers an update. It gets re-drawn.

Thats why as i got higher, each append took more time.

Thanks for the help