How to pass a lv_chart_series_t* from an array to lv_chart_set_next_value()

Description

I declare chart series globally:

lv_chart_series_t * ser0;
lv_chart_series_t * ser1;

then I make an array with these (also in global declaration).

lv_chart_series_t * allSeries[] = {ser0,ser1};

So if I get it right, allSeries is now a pointer to an array of pointers to data series.

I add the series to the chart when initializing it.

chart=lv_chart_create(scrTrend);
ser0 = lv_chart_add_series(chart, lv_palette_main(ser0Color), LV_CHART_AXIS_PRIMARY_Y);

When I want to pass them, the code compiles, but nothing happens…

lv_chart_set_next_value(chart, (lv_chart_series_t *) allSeries[0], value));

if i replace “(lv_chart_series_t *) allSeries[0]” with “ser0”, it works. What is the difference between the 2?

What MCU/Processor/Board and compiler are you using?

ESP32/CYD, VScode/Platformio/Arduino

What LVGL version are you using?

9.1

What do you want to achieve?

Pass a lv_chart_series_t* from an array to lv_chart_set_next_value()

What have you tried so far?

every syntax for casting I could come up with :confused:

it seems like allSeries[] initilized in compile time with ser0, ser1 values wich as far as i understand is NULL.
try

allSeries[0] = lv_chart_add_series(chart, lv_palette_main(ser0Color), LV_CHART_AXIS_PRIMARY_Y);```
1 Like

Thank you very much, that works.

Obviously something with my understanding of of pointers is terribly wrong.
I deliberatly initialized that array with series containing NULL values.

I thought that if I have a pointer to an array of “pointer to chart_series_t”, I should be able to modify the chart_series later, and it be reflected in the array.
I still can’t wrap my head around these things in C++, I am used to C#.

Need to dig into it.