Declare variable ui_chart_x_series_x globally

What do you want to achieve?

In order to add points to the chart series I need to access the variable “ui_chart_x_series_x” in the main code, e.g. in this way:
lv_chart_set_next_value(ui_chartSignal, ui_chartSignal_series_1, signal);

But this is not possible because that var is local in ui.c.
I am using the latest version 1.2.2.

Do you see alternative options and workaround to achieve it?

The only way I see is to change the file ui.c to declare that var globally and add the respective extern declaration in ui.h.
This is not a good solution because my changes are lost every time I export new ui files.

Is there any other way to add points to the chart series without modifying ui.c?

Mention some use cases

1 Like

Thank you for pointing it out. We will fix it in the next version.

Until that you can iterate through the series with lv_chart_get_series_next.

3 Likes

Came across the same issue today. The chart series variable is locally defined in screen ‘c’ file. You just need to do declare it in ui.h and it’s good to go.

My feature recommendations:

  1. Set series name in SLS. Right now it just series_1,2,3,etc.

  2. Series data is charted as a LIFO array from right to left. It helps to initialize all series values with ‘0’ if series data is left empty. If adding series data in SLS, pad with ‘0’ remaining values until series end. (this will ensure no random values will ever be displayed on device)

1 Like

@razvan Both make sense.

We can allow naming the series and make them public in ui.h.

Padding the data of the series with zeros is also a quite reasonable idea.

1 Like

any progress on this topic? struggle to add new data points to a chart

Not yet, I’ll push the developers to add it in the next version.

Thanx @razvan After your suggestion, Its working correctly
in ui.c added
lv_chart_series_t * ui_Chart3_series_1 after lv_obj_t * ui_Chart3;
Also declare in ui.h
extern lv_chart_series_t * ui_Chart3_series_1; after extern lv_obj_t * ui_Chart3;
And call
lv_chart_set_next_value(ui_Chart3, ui_Chart3_series_1, current); in main.c

1 Like