Plot xy graph using uneven points for x axis

How to plot a graph with unevenly distributed points for the X-axis

I have a project based on ESP32 and LVGL-V8.3.11.
I need to plot a graph in which the X-axis points are not distributed evenly.
For example:

int16_t x[] = {0, 2, 4, 8, 9, 10, 15, 18, 25, 38, 39, 41};
int16_t y[] = {0, 1, 12, 18, 20, 23, 30, 33, 28, 20, 14, 8};

This will look like this:

If I use y to create a chart, the graph does not represent the real shape of the data. It will look like this:
Screenshot 2024-11-05 084406

I’ve seen a couple of posts about controlling the X-axis. For example, this post described how to set the tick values. However, the points are equally distributed.
I also ran into a post that suggested using a container and lines to create a custom chart.

Is there a way to create such a graph using the chart?

Could you please provide an example image? This might help us better understand your needs.

Added two images to the question :+1:

int16_t x = { 0, 2, 4, 8, 9, 10, 15, 18, 25, 38, 39, 41 };
int16_t y = { 0, 1, 12, 18, 20, 23, 30, 33, 28, 20, 14, 8 };

static void chart_draw_event_cb(lv_event_t e)
{
lv_obj_t
chart = lv_event_get_target(e);
lv_event_code_t code = lv_event_get_code(e);
if (code == LV_EVENT_DRAW_PART_BEGIN)
{
lv_obj_draw_part_dsc_t* dsc = lv_event_get_draw_part_dsc(e);

    if (dsc->id == LV_CHART_AXIS_PRIMARY_X && dsc->text) {
        lv_snprintf(dsc->text, dsc->text_length, "%d", x[dsc->value]);
    }
    
}

}

/**

  • Add ticks and labels to the axis and demonstrate scrolling
    */
    int app_chart_3(lv_obj_t parent)
    {
    lv_obj_t
    chart = lv_chart_create(lv_scr_act());
    lv_obj_set_size(chart, 600, 200);
    lv_obj_center(chart);

    lv_chart_set_axis_tick(chart, LV_CHART_AXIS_PRIMARY_Y, 10, 5, 6, 5, true, 40);
    lv_chart_set_axis_tick(chart, LV_CHART_AXIS_PRIMARY_X, 10, 5, 12, 1, true, 30);

    lv_chart_series_t* ser = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_RED), LV_CHART_AXIS_PRIMARY_Y);

    uint8_t i;
    for (i = 0; i < 12; i++) {
    lv_chart_set_next_value(chart, ser, y[i]);
    }

    lv_chart_refresh(chart); /Required after direct set/

    lv_obj_add_event_cb(chart, chart_draw_event_cb, LV_EVENT_DRAW_PART_BEGIN, NULL);

    return 0;
    }