cancel
Showing results for 
Search instead for 
Did you mean: 

How to use graph to create two lines and add data to each.

lxw
Senior

I want to use graph drawing 2 line, in the MainView: : handleTickEvent () used in the graph. addDataPoint () to add data respectively?

Another requirement, line needs to be separated by some pixels, how to set.:face_with_tears_of_joy:

12 REPLIES 12
ktrofimo
Senior III

You need to add second line for DynamicGraph widget. And call addDataPoint() twice:

graph.addDataPoint( Value1 );

graph2.addDataPoint( Value2 );

  What I want is to draw two lines in a graph. Can only one line be drawn in a graph?

 dynamicGraph1.addGraphElement(dynamicGraph1Line1);

  dynamicGraph1.addGraphElement(dynamicGraph1Line2);

You can add many lines on the same DynamicGraph in TouchGFX Designer. Use them like the first one.

Here is my test: the first graph (yellow) is sine with random noise and second one (blue) is slider value (61)

0693W00000DpmyDQAR.jpg

 dynamicGraph1.addGraphElement(dynamicGraph1Line1);

  dynamicGraph1.addGraphElement(dynamicGraph1Line2);

​

MainView: : handleTickEvent ()

{

dynamicGraph1.addDataPoint( Value1 );

}​

In this way, the actual display is 2 identical lines, and it looks like one.

I wonder how to add data to different lines using graph.addDatapoint ():face_with_tears_of_joy:

dynamicGraph1 in your code is a line. You need another line object with different data:

MainView: : handleTickEvent ()

{

dynamicGraph1.addDataPoint( Value1 );

dynamicGraph2.addDataPoint( Value1+10 );

}​

This way you will have two parallel lines with 10 points distance

OK, it's OK for a graph to contain a line. But WHAT I'm curious about is how do you make it possible to have multiple lines in a graph?

Another question, how to adjust the red area of line, hoping to leave some space between the old data and the new data

0693W00000DpnEkQAJ.png

ktrofimo
Senior III

Your picture is a SINGLE graph line. This is a method of drawing large amount of data points when new data is overwrites old one in a circular buffer.

Take a note of X axis labels: 1270-1300 is an old data being replaced by new one (1300-1360)

lxw
Senior

Yes, how do I make Xnew = (Xold+100), keep the gap equal to 100

Can you draw what exactly you need on a sheet of paper?