1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00
lvgl/examples/widgets/chart/lv_example_chart_1.c

33 lines
960 B
C
Raw Normal View History

2021-04-08 13:07:48 +02:00
#include "../../lv_examples.h"
2021-02-14 14:56:34 +01:00
#if LV_USE_CHART && LV_BUILD_EXAMPLES
2021-02-08 09:53:03 +01:00
2023-10-16 23:43:27 +02:00
/**
* A very basic line chart
*/
2021-02-08 09:53:03 +01:00
void lv_example_chart_1(void)
{
/*Create a chart*/
lv_obj_t * chart;
chart = lv_chart_create(lv_screen_active());
2021-02-08 09:53:03 +01:00
lv_obj_set_size(chart, 200, 150);
lv_obj_center(chart);
2021-02-08 09:53:03 +01:00
lv_chart_set_type(chart, LV_CHART_TYPE_LINE); /*Show lines and points too*/
/*Add two data series*/
2023-10-16 23:43:27 +02:00
lv_chart_series_t * ser1 = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_GREEN), LV_CHART_AXIS_PRIMARY_Y);
lv_chart_series_t * ser2 = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_RED), LV_CHART_AXIS_SECONDARY_Y);
2021-02-08 09:53:03 +01:00
2023-10-16 23:43:27 +02:00
uint32_t i;
for(i = 0; i < 10; i++) {
/*Set the next points on 'ser1'*/
lv_chart_set_next_value(chart, ser1, lv_rand(10, 50));
2021-02-08 09:53:03 +01:00
2023-10-16 23:43:27 +02:00
/*Directly set points on 'ser2'*/
ser2->y_points[i] = lv_rand(50, 90);
}
2021-02-08 09:53:03 +01:00
lv_chart_refresh(chart); /*Required after direct set*/
}
#endif