Skip to main content
EWqqr.1
Associate
February 22, 2022
Question

How to add different data for two lines in one dynamic graph?

  • February 22, 2022
  • 4 replies
  • 3408 views

Hi,i want to make a oscilloscope to show two data curve.I found the dynamicgraph can add many lines with different color.BUT i can only use the "addDataPoint" fuction to add one data at one time.So I set the two lines the different LineWidth.

Just like this.

0693W00000Ka2OqQAJ.jpgThese two lines show the same data,becuse the addDataPoint function can just input one variate.0693W00000Ka2RBQAZ.pngI want to know how can i draw multiple lines that show the different data in one dynamic graph?

4 replies

ktrofimo
Senior III
February 22, 2022

Every line on the graph will be presented as dynamicGraphX (or whatever you have named it) class.

Then you should add all data at the same time:

dynamicGraph1.addDataPoint( value1 );
dynamicGraph2.addDataPoint( value2 );
dynamicGraph3.addDataPoint( value3 );

EWqqr.1
EWqqr.1Author
Associate
February 22, 2022

0693W00000Ka2e5QAB.pngI just create one dynamicgraph widget,it will be error.

0693W00000Ka2guQAB.pngI want to show these two lines which in the right just in dynamicgraph1.:persevering_face:

ktrofimo
Senior III
February 22, 2022

Check your Screen1ViewBase.hpp header for correct names. They should be of type touchgfx::GraphScroll<NNN> like:

touchgfx::GraphScroll<100> dynamicGraph1;
touchgfx::GraphScroll<100> graph2;
touchgfx::GraphScroll<100> graph3;

Then use those classes.

Osman SOYKURT
Technical Moderator
February 22, 2022

Hello EWqqr.1,

I wouldn't recommend you to use 2 lines elements for a single dynamic graph widget. The easiest way would be to use 2 different widgets like this :

0693W00000Ka4XQQAZ.png 

Be careful to uncheck the boxes on "Vertical Grid Lines", "Horizontal Grid Lines", "X-Axis Labels" and "Y-Axis Labels". That way, you will have 2 independent graph lines in the same view.

0693W00000Ka4W4QAJ.png 

I attached a basic project if you need an example.

/Osman

Osman SOYKURTST Software Developer | TouchGFX
ktrofimo
Senior III
February 22, 2022

It would be nice if you could explain why you do not recommend to use multiple lines with single dynamicGraph object.​

Osman SOYKURT
Technical Moderator
February 22, 2022

It's not the easiest way to do. Indeed the lines are instances of GraphElementLines class, and you can't use addDataPoint() function with them.

Osman SOYKURTST Software Developer | TouchGFX
EWqqr.1
EWqqr.1Author
Associate
February 22, 2022

Thank you all.I create two dynamic graph and align them.The program ran successfully now.

0693W00000Ka4siQAB.jpg

GMeur
Associate III
August 29, 2025

Yeah, it should definitely be improved