cancel
Showing results for 
Search instead for 
Did you mean: 

Reset Graph X Values

Michael K
Senior III

I'm using the dynamic graph to represent a small dataset. The data is acquired all at once through a back-end process, leaving me with an array of around 1000 datapoints. Once acquisition is complete, I use the following code to refresh the graph.

graphWidget.clear();
for (int i = 0; i < size; i++) {
	graphWidget.addDataPoint(yValues[i]);
}
graphWidget.invalidate();

This works sort-of, however the X value labels also increment by size. I want them to restart from 0. I assumed .clear() would do this, but apparently not.

How can I reset the graph and labels back to a fully empty state, such that I can explicitly get labels starting from 0 again? Attached photo shows current (undesirable) behavior.

Solved. Thanks @Vladimir​ 

Open AbstractDataGraph.hpp and scroll down to the AbstractDataGraphWithY class definition, around line 995. Add the following method to the HPP file.

void dataCounterReset() { dataCounter = 0; }

In your View code, call the method to reset the x-axis labels.

Embedded UI/UX Consulting: cadenza.design
1 ACCEPTED SOLUTION

Accepted Solutions
Vladimir1
Associate II

I am using the following workaround:

1. After adding points using addDataPoint(), the dataCounter field of the AbstractDataGraphWithY class is incremented. In this class, I have added a dataCounterReset () function that zeroes out the dataCounter.

2. Before adding points to dynamicGraph, I called the dataCounterReset () function.

2. Then, in the properties of Middlewares / ST / touchgfx, unchecked the "Exclude resource from assembly build" checkbox and compiled the project.

I also did not find another way.

View solution in original post

18 REPLIES 18
GPa.1
Associate III

Hi Michael,

Did you find how to solve it? I have the same issue, i tried different approaches but without success.

Hi, no luck yet unfortunately.

Embedded UI/UX Consulting: cadenza.design
Vladimir1
Associate II

I am using the following workaround:

1. After adding points using addDataPoint(), the dataCounter field of the AbstractDataGraphWithY class is incremented. In this class, I have added a dataCounterReset () function that zeroes out the dataCounter.

2. Before adding points to dynamicGraph, I called the dataCounterReset () function.

2. Then, in the properties of Middlewares / ST / touchgfx, unchecked the "Exclude resource from assembly build" checkbox and compiled the project.

I also did not find another way.

Thank you, this worked for me. Hopefully ST implements this as an official feature in the next release.

Edit: the exact thing that worked was adding the following code to the public section of the AbstractDataGraphWithY class declaration in AbstractDataGraph.hpp:

void dataCounterReset() { dataCounter = 0; }

Line 994 on my system. I didn't have to exclude any resources from the build. Make a note wherever you use it to remind yourself to add it back in every time you update TouchGFX.

Embedded UI/UX Consulting: cadenza.design

I second this proposal, this is quite common application

Hi @Vladimir​ ,

Do you have the code snippet please?

Where should I download the sample code you described?