How to use lv_chart_set_x_tick_length() , lv_chart_set_x_tick_texts() and etc

Description

I tried to use

lv_chart_set_x_tick_length(…)
lv_chart_set_x_tick_texts(…)
lv_chart_set_y_tick_length(…)
lv_chart_set_y_tick_texts(…)

But it seems no effect about these apis.
Is there any example a chart with these apis?

Thank you.

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

  • ESP32

What do you want to achieve?

  • Change x-axis, y-axis tick and label.

What have you tried so far?

Code to reproduce

Screenshot and/or video

Did you read the relevant part of the documentation?

I checked and there doesn’t seem to be an example for this. There is a code snippet here.

1 Like

@embeddedt
Thank you very much.

By the code snippet, I tested the code by the following on the lastest lvgl dev-6.1.

Code

  static lv_style_t style; lv_style_copy(&style, &lv_style_plain);
    style.text.color = LV_COLOR_WHITE; 
    style.line.width = 1;
    style.line.opa   = 128;
    
  lv_obj_t* chart = lv_chart_create(lv_scr_act(),NULL);
    lv_obj_set_size(chart,180,120);
    lv_obj_align(chart, NULL, LV_ALIGN_CENTER, 0,0);
    lv_obj_set_style(chart, &style);
    
    lv_chart_set_x_tick_texts(chart, "1\n2\n3\n4\n5\n6\n7", 2, LV_CHART_AXIS_DRAW_LAST_TICK);
    lv_chart_set_x_tick_length(chart, 5, 8);
    lv_chart_set_y_tick_texts(chart, "123\n456\n789\n5a\n", 2, LV_CHART_AXIS_DRAW_LAST_TICK | LV_CHART_AXIS_INVERSE_LABELS_ORDER);
    lv_chart_set_y_tick_length(chart, 5, 8);


  lv_chart_set_type(chart, LV_CHART_TYPE_LINE | LV_CHART_TYPE_POINT );
    serie1 = lv_chart_add_series(chart, LV_COLOR_RED);
    lv_chart_set_next( chart, serie1, random(100));
    lv_chart_set_next( chart, serie1, random(100));
    lv_chart_set_next( chart, serie1, random(100));
    lv_chart_set_next( chart, serie1, random(100));
    lv_chart_set_next( chart, serie1, random(100));
    lv_chart_set_next( chart, serie1, random(100));
    lv_chart_set_next( chart, serie1, random(100));
    lv_chart_set_next( chart, serie1, random(100));

Result

The issue still shows nothing about x, y-axis texts.

image

You need to set some margin to enable drawing outside of the chart e.g. lv_chart_set_margin(chart, 40);

See the docs here.

1 Like