cancel
Showing results for 
Search instead for 
Did you mean: 

How to add X/Y line chart with multiple series

Louie88
Associate III

I have my own TouchGFX App running on STM32H747I-DISCO board. It reads data from popular BME280 sensor chip via I2C interface. Now I need to show the "history" of measured temperature, pressure and humidity on a graph underneath the RTC date, day of week and time of day display (Clock).

I picked Dynamic Graph first because it can show the last (say) 400 measured data and scrolls it automatically when I add a new data point. Then I realized that Dynamic Graph does not support custom X/Y data.: I can add the Y data only: graph.addDataPoint(float yValue). Too bad. I also noticed that everything is stored as integer, not as float type number )For performance I guess). And last but not least I cannot access (read/modify) the added values stored in graph. What is good for such a graph?

Then I switched to Static Graph. It was a big surprise, but static graph can add X/Y values graph.addDataPoint(float xValue, float yValue). Great. They are still stored as integers but that's okay. Using Scaling and Precision I could simulate float number on the graph.

I set the capacity of the static graph to 400. And here comes the question: what I should do if the graph is full, (it contains 400 X/Y data points) and the 401st sample should be shown. I think it is obvious: I should delete the "oldest X/Y data point" (Index = 0) and I will have 399 X/Y data points in graph. Now I can append then 401st data point to the graph. This way the user still will see 400 data points but from 1 to 401 sample range. This works nice.

As I mentioned earlier that I cannot read X/Y data from the graph so the time (X Axis), the temperature (Y1 axis), the pressure (Y2 axis) and the humidity (Y3 axis) should be stored in own array. (4 x 400 entry float numbers).  In addition, the arrays must be reordered: when deleting the first element every element must be moved to the previous address, to have a room for the new element. It's not nice feature but I solved it. 

Of course, none of the graphs have multi-Y axes, they can store a single Y axis data only. So when the user wants to look at the pressure instead of the temperature, then I have to clear the graph, reload X/Y value from pressure array into the graph. It is clear but it does not work. Once the graph is full (It has 400 samples), clearing it and adding 400 pressures data only a couple of data is added. Instead of 400 pressure data I see 90-100 data. The graph.addDataPoint(float xValue, float yValue) normally returns the index of the new data store in graph's internal array, or -1 if there was error. When the data is not added the method always return index = 0. 

Anyway, I am disappointed. TouchGFX is a good platform, but the graph support is a shame.

Or, of course, I am doing something wrong...

Sorry about the long post!

Louis

 

1 REPLY 1
Louie88
Associate III

Suggestions (Instead of the above long story):

  1. Add graph.addDataPoint(float xValue, float yValue) method to Dynamic Graph. This way the user could show custom data (say time) on the X Axis while scrolling the graph would also be kept. It seems to be a simple change.

It would be nice:

  1. Add Dynamic Behaviour = Disabled button to Graph editor (to the existing behaviour settings WrapAndClear, Scroll, WrapAndOverwrite buttons). When Dynamic Behaviour = Disabled then create a Static Graph. This way you can forget the stand-alone Static Graph control.
  2. Add getXvalue(int index), getYvalue(int index), setXValue(int index, float value)setYValue(int index, float value) methods to read and modify X/Y data point in graph. Also, getXValues(), getYValues() would return then whole array (pointer) while setXValues(float *array, int length), getYValues(float *array, int length) would set an array into the graph.
  3. Add setMaxCapacity(int value) method to change size of the internal data array from code. Currently it can only be changed when the GrpahXXX is created in the hpp file..
  4. Change the X/Y arrays to float type in graph. Most of the new, larger MCUs have dedicated floating point units (single/double precision, trigonometrical). I do not think that using float type X/Y data would be too dangerous performance degradation.

I think these suggested changed would make the Graph control much better and at least usable for most of us.

Thanks,

Louis