Skip to main content
Associate II
January 30, 2025
Solved

Plotting large array of data in touchgfx graph

  • January 30, 2025
  • 4 replies
  • 1036 views

Hi,

I am trying to plot an array of 512 values in a dynamic graph in touchgfx. This is working as intended but I am experiencing poor performance. When in histogram mode the graph updates quickly however I wish to use line mode and when in this mode, the graph will take between two and three seconds to update. I'm aiming to get the graph to update in around one second. 

Any ideas on how to optimise the plotting of the graph. Perhaps the way in which the data is passed from Model.cpp into the screenView.cpp?

Currently I am passing the data through as such:

for(int i = 0; i < 512; i++)
{
 modelListener->UpdateGraph(i, graphData[i]);
}

Any help would be greatly appreciated.

Thanks.

This topic has been closed for replies.
Best answer by Osman SOYKURT

Hello @Josh_W020 ,

What is the size of your graph widget? Does it take up the entire size of your display?

This limitation is known to us, and to explain a bit, it's because a graph of 4 points in "Line" mode for instance, will in reality use more than 12 points that need to be calculated (and then some pixels are alpha blended if I recall correctly). In a histogram, it's much easier as the bottom part of the graph is known and easy to render (straight lines of pixels, no calculation is needed).

I have a suggestion that might help you. If you have not one but two graphs (the same), using "Area" as the mode and not Line or histogram, and you place the second graph on top of the first one with a small shift in the Y axis (and with background color/image), then you should be able to have the same visual as the "Line". From my measurements, it's three times more effective that way when rendered. Just a little downside, when there are curves with big gaps in the Y axis, then the line will not look as good as with "Line". To overcome this limitation, you can have your second graph look almost the same but also shift in X (some points you'll have to add 1, some points you'll subtract 1).


Hope this helps.

4 replies

Andrew Neil
Super User
January 30, 2025

@Josh_W020 wrote:

Any ideas on how to optimise the plotting of the graph. .


Do you really need to plot all the values?

eg, could you just plot every fourth? Maybe averaged?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Josh_W020Author
Associate II
January 30, 2025

Yes unfortunately its important that all values are plotted as it needs to be a high accuracy representation of a recorded frequency.

 

Osman SOYKURT
Technical Moderator
January 30, 2025

Hello @Josh_W020 ,

Could you try to increase your canvas buffer and see if it's better?

Osman SOYKURTST Software Developer | TouchGFX
Josh_W020Author
Associate II
January 30, 2025

Tried doubling this from 12000 to 24000 but didn't see any difference.

Osman SOYKURT
Osman SOYKURTBest answer
Technical Moderator
February 14, 2025

Hello @Josh_W020 ,

What is the size of your graph widget? Does it take up the entire size of your display?

This limitation is known to us, and to explain a bit, it's because a graph of 4 points in "Line" mode for instance, will in reality use more than 12 points that need to be calculated (and then some pixels are alpha blended if I recall correctly). In a histogram, it's much easier as the bottom part of the graph is known and easy to render (straight lines of pixels, no calculation is needed).

I have a suggestion that might help you. If you have not one but two graphs (the same), using "Area" as the mode and not Line or histogram, and you place the second graph on top of the first one with a small shift in the Y axis (and with background color/image), then you should be able to have the same visual as the "Line". From my measurements, it's three times more effective that way when rendered. Just a little downside, when there are curves with big gaps in the Y axis, then the line will not look as good as with "Line". To overcome this limitation, you can have your second graph look almost the same but also shift in X (some points you'll have to add 1, some points you'll subtract 1).


Hope this helps.

Osman SOYKURTST Software Developer | TouchGFX
Josh_W020Author
Associate II
February 18, 2025

Thats a good suggestion however as the graph will often need to plot high frequencies with large variation in y axis, i don't think the work around you suggested would be usable? 

 

Thanks anyway,

Josh

 

Osman SOYKURT
Technical Moderator
May 13, 2025

Hello @Josh_W020 ,

Have you been able to overcome your issue?

Osman SOYKURTST Software Developer | TouchGFX