Several questions problems about chart widget

Important: unclear posts may not receive useful answers.

Before posting

  • Get familiar with Markdown to format and structure your post
  • Be sure to update lvgl from the latest version from the master branch.
  • Be sure you have checked the relevant part of the documentation.
  • If applicable use the Simulator to eliminate hardware related issues.

Delete this section if you read and applied the mentioned points.

Description

I have several questions about using chart widget

  1. If I add 4 series to a chart, how to hide one or more series in some case?
  2. In the docs example lv_example_chart_5, how to show the x axis value of pressed points?
  3. In the lv_example_chart_6 has an API called lv_obj_draw_part_check_type, but I didn’t found it in version 8.0.1? Is it a mistake?

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

What LVGL version are you using?

8.0.1

What do you want to achieve?

What have you tried so far?

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*/

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

You can use lv_chart_hide_series(chart, series, true);.

See this as an example:
Examples — LVGL documentation

It was introduced for v8.1.0 so it’s in master. I suggest updating LVGL from the master branch.

As for the second question, in lv_example_chart_5 I display 1000 data with zoom, then I want to show the x axis ,range from 1~1000, and I add some codes in the examples

lv_chart_set_range(chart, LV_CHART_AXIS_PRIMARY_X, 1, 1000);
lv_chart_set_axis_tick(chart, LV_CHART_AXIS_PRIMARY_X, 10, 5, 20, 2, true, 50);

but it seems still show the range 0~19 in the x axis.

Another quesion, in lv_example_chart_4 it can show the value of the point, I combine this example with lv_example_chart_5(it mean display 1000 points and can show the pressed point value), now I want to show the x axis when I pressed one point, so I add some codes

  lv_coord_t* x_array = lv_chart_get_x_array(chart, ser);
 lv_coord_t value_x = x_array[id];

lv_snprintf(buf, sizeof(buf), LV_SYMBOL_DUMMY"%d, %d", value_x, value_y);

and found it value_x is wrong, it shows an error numbur, can u tell me how it happens? Is there something I miss?

I know, lv_chart_get_x_array need the point array in x axis, but I add the series to the y array.
So, I should printf id instead of value_x

The X range can be used on with SCATTER chart type. Try this:

lv_snprintf(buf, sizeof(buf), LV_SYMBOL_DUMMY"%d, %d", id, value_y);

Yes :slight_smile:

Thanks, I tried lv_chart_set_type(chart, LV_CHART_TYPE_SCATTER),the line becomes wired and the chart_event_cb seems can’t show the pressed point value.

Why do you use a scatter chart? Scatter chart allows setting both the x and y value. See here.

It seemed to me you need a simple line chart.

I need to show a large points chart(most 30000 data points)

The line chart is fine for that.

Yes, so if I used the line chart to show 30000 datas, and I use the zoom effect, then how to set X axis to show the range from 1~30000 while the chart is zooming

Ah, I see. So want to keep the div lines and axis ticks not zoomed, right?

The fact is , based on the code of lv_example_chart_5, I add the Y axis tick by lv_chart_set_axis_tick(), it shows the Y axis tick well. Then I add the X axis tick by lv_chart_set_axis_tick(chart, LV_CHART_AXIS_PRIMARY_X, 10, 5, 20, 2, true, 50), the number of major ticks on the axis is 20, so the expected tick labels should be “0, 1500, 3000 …”, for I set the range is (0, 30000), but in fact it shows 0, 1, 2, …19, it seems it’s worthless by set X axis tick in the lv_example_chart_5

It because you set 20 major ticks.

It sets 100:

    lv_chart_set_axis_tick(chart, LV_CHART_AXIS_PRIMARY_X, 10, 5, 100, 2, true, 50);

Probably you should set it dynamically based on the zoom level.