Is it correct that the function lv_chart_get_point_pos_by_id() gets the coordinate value of the point?

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 FAQ and read 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

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

ESP32-S3

What LVGL version are you using?

v8.3.2

What do you want to achieve?

Display values in a point location in a chart

What have you tried so far?

Attempted to import coordinate values with function lv_chart_get_point_pos_by_id().
However, the coordinate values are expressed strangely.

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

lv_obj_t * panel1 = lv_obj_create(lv_scr_act());
lv_obj_remove_style_all(panel1);
lv_obj_set_size(panel1, 420, 380);
lv_obj_set_pos(panel1, 60, 0);
lv_obj_add_style(panel1, &Weather_Value_Style, 0);
lv_obj_set_scroll_dir(panel1, LV_DIR_LEFT | LV_DIR_RIGHT);

static lv_style_t chart_style;
lv_style_init(&chart_style);
lv_style_set_border_color(&chart_style, lv_color_white());

lv_obj_t * chart;
chart = lv_chart_create(panel1);

lv_chart_set_div_line_count(chart, 0, 0);
lv_obj_set_pos(chart, 15, 130);
lv_obj_add_style(chart, &chart_style, 0);

lv_chart_series_t * ser1 = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_BLUE), LV_CHART_AXIS_PRIMARY_Y);
lv_chart_set_point_count(chart, 72);
lv_chart_set_type(chart, LV_CHART_TYPE_LINE);

int Axis_X = -180;
for(int i = 0; i < 72; i++){
if(i != 0)Axis_X += 60;

lv_obj_t *Weather_Value_Time_Text = lv_label_create(panel1);
lv_label_set_text_fmt(Weather_Value_Time_Text, "%d시", Hour_data[i]);
lv_obj_set_style_text_align(Weather_Value_Time_Text, LV_TEXT_ALIGN_CENTER, 0);
lv_obj_align(Weather_Value_Time_Text, LV_ALIGN_CENTER, Axis_X, -140);

lv_obj_t *Weather_Value_Img = lv_img_create(panel1);
if(Weather_data[i] == 1){
  if(Hour_data[i] < 8 || Hour_data[i] > 17)lv_img_set_src(Weather_Value_Img, &Clear_N);
  else lv_img_set_src(Weather_Value_Img, &Clear_S);
}
if(Weather_data[i] == 2){
  if(Hour_data[i] < 8 || Hour_data[i] > 17)lv_img_set_src(Weather_Value_Img, &Mostly_Cloudy_N);
  else lv_img_set_src(Weather_Value_Img, &Mostly_Cloudy_S);
}
if(Weather_data[i] == 3)lv_img_set_src(Weather_Value_Img, &Cloudy);
if(Weather_data[i] == 4)lv_img_set_src(Weather_Value_Img, &Rain);
if(Weather_data[i] == 5)lv_img_set_src(Weather_Value_Img, &Rain_Snow);
if(Weather_data[i] == 6)lv_img_set_src(Weather_Value_Img, &Snow);
if(Weather_data[i] == 7)lv_img_set_src(Weather_Value_Img, &shower);
if(Weather_data[i] == 8)lv_img_set_src(Weather_Value_Img, &Raindrop);
if(Weather_data[i] == 9)lv_img_set_src(Weather_Value_Img, &Raindrop_Snow);
if(Weather_data[i] == 10)lv_img_set_src(Weather_Value_Img, &Snow_Drifting);
lv_obj_align(Weather_Value_Img, LV_ALIGN_CENTER, Axis_X, -90);

lv_chart_set_next_value(chart, ser1, Temp_data[i]);

lv_obj_t *Weather_Value_Humidity_Text = lv_label_create(panel1);
lv_label_set_text_fmt(Weather_Value_Humidity_Text, "%d%%", Humidity_data[i]);
lv_obj_set_style_text_align(Weather_Value_Humidity_Text, LV_TEXT_ALIGN_CENTER, 0);
lv_obj_align(Weather_Value_Humidity_Text, LV_ALIGN_CENTER, Axis_X, 60);

lv_obj_t *Weather_Value_Rain_Text = lv_label_create(panel1);
float rain = Rain_data[i];
if(rain == 0)lv_label_set_text(Weather_Value_Rain_Text, "-");
if(rain > 0 && rain < 1)lv_label_set_text(Weather_Value_Rain_Text, "~1");
if(rain >= 1){
  char rain_str[10];
  if (rain == static_cast<int>(rain))snprintf(rain_str, sizeof(rain_str), "%d", static_cast<int>(rain));
  else dtostrf(rain, 4, 1, rain_str);
  const char* rain_const = rain_str;
  lv_label_set_text(Weather_Value_Rain_Text, rain_const);
}
lv_obj_set_style_text_align(Weather_Value_Rain_Text, LV_TEXT_ALIGN_CENTER, 0);
lv_obj_align(Weather_Value_Rain_Text, LV_ALIGN_CENTER, Axis_X, 110);

lv_obj_t *Weather_Value_Rain_Per_Text = lv_label_create(panel1);
lv_label_set_text_fmt(Weather_Value_Rain_Per_Text, "%d%%", Rain_Per_data[i]);
lv_obj_set_style_text_align(Weather_Value_Rain_Per_Text, LV_TEXT_ALIGN_CENTER, 0);
lv_obj_align(Weather_Value_Rain_Per_Text, LV_ALIGN_CENTER, Axis_X, 160);

}

lv_chart_set_range(chart, LV_CHART_AXIS_PRIMARY_Y, low_temp, high_temp + 5);
lv_obj_set_size(chart, Axis_X+200, 110);

lv_chart_refresh(chart);

for(int i = 0; i < 72; i++){
lv_point_t p;
lv_chart_get_point_pos_by_id(chart, ser1, i, &p);
Serial0.print(“i:”);Serial0.print(i);
Serial0.print(“, x:”);Serial0.print(p.x);
Serial0.print(“, y:”);Serial0.println(p.y);
lv_obj_t *Weather_Temp_Text = lv_label_create(chart);
lv_label_set_text_fmt(Weather_Temp_Text, “%d”, Temp_data[i]);
lv_obj_set_style_text_align(Weather_Temp_Text, LV_TEXT_ALIGN_CENTER, 0);
lv_obj_set_pos(Weather_Temp_Text,p.x,p.y);
}

Serial print

i:0, x:12, y:3
i:1, x:12, y:3
i:2, x:12, y:1
i:3, x:11, y:1
i:4, x:11, y:0
i:5, x:11, y:-2
i:6, x:10, y:-2
i:7, x:10, y:-4
i:8, x:10, y:-6
i:9, x:9, y:-6
i:10, x:9, y:-6
i:11, x:9, y:-6
i:12, x:8, y:-6
i:13, x:8, y:-6
i:14, x:8, y:-6
i:15, x:7, y:-4
i:16, x:7, y:-6
i:17, x:7, y:-6
i:18, x:6, y:-6
i:19, x:6, y:-7
i:20, x:6, y:-7
i:21, x:5, y:-9
i:22, x:5, y:-7
i:23, x:5, y:-7
i:24, x:4, y:-9
i:25, x:4, y:-9
i:26, x:4, y:-9
i:27, x:3, y:-9
i:28, x:3, y:-11
i:29, x:3, y:-11
i:30, x:2, y:-11
i:31, x:2, y:-11
i:32, x:2, y:-11
i:33, x:1, y:-12
i:34, x:1, y:-11
i:35, x:1, y:-11
i:36, x:0, y:-9
i:37, x:0, y:-7
i:38, x:0, y:-7
i:39, x:-1, y:-6
i:40, x:-1, y:-6
i:41, x:-1, y:-7
i:42, x:-2, y:-7
i:43, x:-2, y:-9
i:44, x:-2, y:-9
i:45, x:-3, y:-9
i:46, x:-3, y:-9
i:47, x:-3, y:-9
i:48, x:-4, y:-11
i:49, x:-4, y:-11
i:50, x:-4, y:-11
i:51, x:-5, y:-11
i:52, x:-5, y:-12
i:53, x:-5, y:-12
i:54, x:-6, y:-12
i:55, x:-6, y:-12
i:56, x:-6, y:-12
i:57, x:-7, y:-12
i:58, x:-7, y:-11
i:59, x:-7, y:-9
i:60, x:-8, y:-7
i:61, x:-8, y:-6
i:62, x:-8, y:-4
i:63, x:-9, y:-4
i:64, x:-9, y:-4
i:65, x:-9, y:-4
i:66, x:-10, y:-4
i:67, x:-10, y:-6
i:68, x:-10, y:-7
i:69, x:-11, y:-7
i:70, x:-11, y:-9
i:71, x:-12, y:-11

Hello, how do you fill the chart? It looks like these are the actual coordinates of the chart, not the coordinates in the total display.

Hello, Tinus.
I didn’t understand what you were saying.

Do you mean where you put data in the chart?

Yes, can you show me the code where you put the data in the chart?

The code is also included in the code I posted. “lv_chart_set_next_value (chart, ser1, Temp_data[i])”
This is where the hourly temperature value is stored in Temp_data and the data is entered by repeating it 72 times.