How to assign specific (round) values to ticks on a chart?

How to assign ticks on a chart a specific (round) value?

I’m creating a chart, where the X axis is a time axis. Time is passing, and my X axis range is moving with it:

  lv_chart_set_axis_tick(chart, LV_CHART_AXIS_PRIMARY_X, 5, 5, 5, 1, true, 30);

  if (real_time < 1000) {
    lv_chart_set_range(chart, LV_CHART_AXIS_PRIMARY_X, 0, 1000);
  } else {
    lv_chart_set_range(chart, LV_CHART_AXIS_PRIMARY_X, real_time - 1000,
                       real_time);
  }

But the ticks have assigned values that are equal to max_range/num_of_ticks, which is not what I want. I’d like the ticks to represent the round numbers and move along as the chart advances. example images

I don’t think I’m explaining it clearly, but the pictures show it: I want to make a chart so that the ticks are not dependent on current range, but are round values that can be seen on the chart at the moment.

The picture of a screen is my current set up, with drawn-on the desired effect, and the screenshot is what I want to achieve.

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

ESP32 on Sunton 8048S070-C

What LVGL version are you using?

8.3

I’ve found my answer!

I selected a much bigger, round range and zoomed in a chart to display only the part which I wanted, disabled scrolling but scroll from the code instead of changing range.

To make this work when you don’t know the range before is to just each time you exceed it make it an even bigger round number and modify the number of ticks!

The tricky part was scrolling with a good speed, so only a certain range was visible and the newest point was in line with the maximum visible (after zooming in) range - but I just did not know how many pixels are inside the chart area - since I set it with lv_obj_set_size(chart, 600, 300); I assumed it was 600 - but it was actually 574, so the final code looks like this:
In init:

  lv_chart_set_zoom_x(chart, zoom*256);

And in loop:

  lv_coord_t max_px =574.0 * (double)zoom;
  double factor = (double)(last_x_value - range_in_view_x) / (double) max_range_x;
  int goal = (double)max_px * factor;
  lv_obj_scroll_to(chart, goal, 0, LV_ANIM_OFF);
  } else {
  lv_obj_scroll_to(chart, 0, 0, LV_ANIM_OFF);

Thus allowing me to see only the range_in_view_x range on the X axis while having the ticks show round values.