How to use Lv_chart_set_value_by_id2() to plot specific data?

Description

I have a function that is called to plot scatter x-y data on chart. The API function lv_chart_set_next_value2(chart_op, ser_st, x, y) is used to plot data no the chart, is work well :

void plot_st_data(uint16_t x, uint16_t y) {
    uint16_t id_data = x / dt;
    //lv_chart_set_value_by_id2(chart_op, ser_st, id_data, x, y);
    lv_chart_set_next_value2(chart_op, ser_st,  x, y);
    printf("plot data : id=%d , x=%d, y=%d \n", id_data, x, y);
    //lv_chart_refresh(chart_op);
    //lv_refr_now(NULL);
}

In order to modify the specific data, the API
lv_chart_set_next_value2(chart_op, ser_st, x, y)
is replaced with
lv_chart_set_value_by_id2(chart_op, ser_st, id_data, x, y);

But lv_chart_set_value_by_id2() does not work correctly, there is not thing on the chart.

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

VisualStudio Simulator

What LVGL version are you using?

v8.0

What do you want to achieve?

Use the API lv_chart_set_value_by_id2(chart_op, ser_st, id_data, x, y) to plot chart, hence the specific data can be modified via id_data.

What have you tried so far?

I replace lv_chart_set_next_value2(chart_op, ser_st, x, y);
with
lv_chart_set_value_by_id2(chart_op, ser_st, id_data, x, y);

But it does not work correctly.
BTW, I have checked the API lv_chart_set_value_by_id2(chart_op, ser_st, id_data, x, y); in lv_example_chart_7, It’s work correctly!

Code to reproduce

void plot_st_data(uint16_t x, uint16_t y) {
    uint16_t id_data = x / dt;
    lv_chart_set_value_by_id2(chart_op, ser_st, id_data, x, y);
    //lv_chart_set_next_value2(chart_op, ser_st,  x, y);
    printf("plot data : id=%d , x=%d, y=%d \n", id_data, x, y);
    lv_chart_refresh(chart_op);
    lv_refr_now(NULL);
}

Thanks for your suggestion, Best Wishes.

I make a simple test on lv_example_chart_7.
the code are shown as following:
case 1:

lv_chart_set_point_count(chart, 50);
    uint16_t x, y;
    uint32_t id = 0;
    for(i = 0; i < 10; i++) {
        x = lv_rand(0, 200); y = lv_rand(0, 1000);
        id = i*2;
        lv_chart_set_value_by_id2(chart, ser, i, x, y);
        printf("%dth data : id=%d  x=%d   y=%d \n", i, id, x, y);
     //   Sleep(2000);
        //lv_chart_refresh(chart);
        lv_refr_now(NULL);
        t = 0;
        Sleep(1000);
        //system("pause");
    }

case 2

lv_chart_set_point_count(chart, 50);
    uint16_t x, y;
    uint32_t id = 0;
    for(i = 0; i < 10; i++) {
        x = lv_rand(0, 200); y = lv_rand(0, 1000);
        id = i*2;
        lv_chart_set_value_by_id2(chart, ser, id, x, y);
        printf("%dth data : id=%d  x=%d   y=%d \n", i, id, x, y);
     //   Sleep(2000);
        //lv_chart_refresh(chart);
        lv_refr_now(NULL);
        t = 0;
        Sleep(1000);
        //system("pause");
    }

In the case1, the id API chart_set_value_by_id2() is set as i and is increated one by one. It work well.

In the case 2, the id in API chart_set_value_by_id2() is set as id=i*2, it work incorrectly.


not thing on the chart!

BTW, I also test the case of id=i+10, It work well.
Hence, I suggest that ser->x_point[id] and ser->y_point[id] must be assigned continues.