Lv_chart_set_axis_tick does not work for x axis

Description

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

What LVGL version are you using?

v 9.0.0

What do you want to achieve?

What have you tried so far?

I am noticing an issue with X axis ticks not appearing. The Y axis works absolutely alright for me. The lvgl chart type I am using is none and I am using setting the data range for the x axis as 0 to 50000

This is a small snippet of my code -
/* Create a pl_gui_fft_chart for displaying axises (not for actual data display) */
chart = lv_chart_create(parent);
lv_chart_set_type(chart, LV_CHART_TYPE_NONE);
lv_obj_set_size(chart, 600, 340);
lv_obj_set_pos(chart, 30, 50);

lv_chart_set_range(chart,
	LV_CHART_AXIS_PRIMARY_X,
	0,
	25000);
lv_chart_set_axis_tick(chart,
	LV_CHART_AXIS_PRIMARY_X,
	5,
	0,
	10,
	1,
	true,
	50);

/* Display labels on x and y axises */
lv_chart_set_axis_tick(chart,
	LV_CHART_AXIS_PRIMARY_Y,
	5,
	0,
	9,
	1,
	true,
	100);

/* Set the x and y axises range (input data range) */
lv_chart_set_range(chart,
	LV_CHART_AXIS_PRIMARY_Y,
	-200,
	0);

lv_chart_refresh(chart);

This same snippet however works if the chart type is changed to Scatter. Have checked with the simulator as well and the x axis ticks are coming as 0 1 2 3 4 and so on

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

/*You code here*/
import lvgl as lv

import display_driver

# Initialize LVGL

lv.init()

# Create a screen object

scr = lv.obj()

# Create a chart object

chart = lv.chart(scr)

chart.set_size(600, 340)

chart.set_pos(30, 50)

chart.set_type(lv.chart.TYPE.NONE) # Set chart type to NONE

# Set the X and Y axis ranges

chart.set_range(lv.chart.AXIS.PRIMARY_X, 0, 50000)

chart.set_range(lv.chart.AXIS.PRIMARY_Y, -200, 0)

# Set axis ticks (this may need adjustments)

chart.set_axis_tick(lv.chart.AXIS.PRIMARY_X, 5, 0, 10, 1, True, 50)

chart.set_axis_tick(lv.chart.AXIS.PRIMARY_Y, 5, 0, 9, 1, True, 100)

# Add a dummy series to trigger X-axis scaling

dummy_ser = chart.add_series(lv.color_hex(0xFF0000), lv.chart.AXIS.PRIMARY_Y)

chart.set_next_value(dummy_ser, 0)

chart.set_next_value(dummy_ser, 50000)

# Force refresh

chart.invalidate()

# Load the screen

lv.scr_load(scr)

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.
This is a SS from the simulator
image

in LVGL9, Perhaps you need to use lv_scale to represent the x-axis
Chart (lv_chart) — LVGL documentation

Thanks for your response. I tried using the lv_scale that did not work for me either and have resorted to an approach like this import lvgl as lv

Initialize LVGL

lv.init()

Create a screen object

scr = lv.obj()

Create a chart for reference (but not rendering data)

chart = lv.chart(scr)
chart.set_size(600, 300)
chart.set_pos(30, 30)
chart.set_type(lv.chart.TYPE.NONE) # No default chart type
chart.set_range(lv.chart.AXIS.PRIMARY_X, 0, 50000)
chart.set_range(lv.chart.AXIS.PRIMARY_Y, -200, 0)

Manually create tick labels along the X-axis

tick_labels = [“0”, “5k”, “10k”, “15k”, “20k”, “25k”, “30k”, “35k”, “40k”, “45k”, “50k”]
tick_spacing = 60 # Adjust this based on chart width
for i, text in enumerate(tick_labels):
lbl = lv.label(scr)
lbl.set_text(text)
lbl.align_to(chart, lv.ALIGN.OUT_BOTTOM_MID, (i - 5) * tick_spacing, 10)

Load the screen

lv.scr_load(scr)

Is there any better way though? Does it work on newer versions of lvgl perhaps?

Hello,

Works on my machine… LVGL 9.2:

    lv_obj_t * wrapper = lv_obj_create(screen);
    lv_obj_remove_style_all(wrapper);
    lv_obj_remove_flag(wrapper, LV_OBJ_FLAG_GESTURE_BUBBLE);

    lv_obj_t * scale_left = lv_scale_create(wrapper);
    lv_scale_set_mode(scale_left, LV_SCALE_MODE_VERTICAL_LEFT);
    lv_scale_set_range(scale_left, -20, 120);
    lv_obj_set_size(scale_left, 50, lv_pct(80));
    lv_obj_set_y(scale_left, 30);
    lv_scale_set_total_tick_count(scale_left, 8);
    lv_scale_set_major_tick_every(scale_left, 1);
    lv_scale_set_label_show(scale_left, true);


    lv_obj_t* chart = lv_chart_create(wrapper);
    lv_obj_align_to(chart, scale_left, LV_ALIGN_OUT_RIGHT_TOP, 0, 0);
    lv_obj_set_style_pad_all(chart, 0, LV_PART_MAIN);
    lv_obj_set_style_size(chart, 0, 0, LV_PART_INDICATOR);
    lv_obj_add_style(chart, &Style_Chart, LV_PART_MAIN); // This just sets padding

    lv_obj_t * scale_bottom = lv_scale_create(wrapper);
    lv_scale_set_mode(scale_bottom, LV_SCALE_MODE_HORIZONTAL_BOTTOM);
    lv_obj_set_size(scale_bottom, lv_obj_get_width(chart), 50);
    lv_scale_set_total_tick_count(scale_bottom, 5);
    lv_scale_set_major_tick_every(scale_bottom, 1);