From 5565d5965a7c8812c807245aca8a1ffe75685374 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Mon, 27 Sep 2021 11:01:31 +0200 Subject: [PATCH] feat(example) chart example to add gap between the old and new data (#2565) * fix(chart) draw line chart indicator (bullet) There was a missing bullet if the previous point was LV_CHART_POINT_NONE * feat(example) add chart example with gap in circular mode * add missing prototype --- examples/widgets/chart/lv_example_chart_9.c | 46 +++++++++++++++++++++ examples/widgets/lv_example_widgets.h | 1 + 2 files changed, 47 insertions(+) create mode 100644 examples/widgets/chart/lv_example_chart_9.c diff --git a/examples/widgets/chart/lv_example_chart_9.c b/examples/widgets/chart/lv_example_chart_9.c new file mode 100644 index 000000000..c94b564fa --- /dev/null +++ b/examples/widgets/chart/lv_example_chart_9.c @@ -0,0 +1,46 @@ +#include "../../lv_examples.h" +#if LV_USE_CHART && LV_DRAW_COMPLEX && LV_BUILD_EXAMPLES + + +static void add_data(lv_timer_t * t) +{ + lv_obj_t * chart = t->user_data; + lv_chart_series_t * ser = lv_chart_get_series_next(chart, NULL); + + lv_chart_set_next_value(chart, ser, lv_rand(10, 90)); + + uint16_t p = lv_chart_get_point_count(chart); + uint16_t s = lv_chart_get_x_start_point(chart, ser); + lv_coord_t * a = lv_chart_get_y_array(chart, ser); + + a[(s + 1) % p] = LV_CHART_POINT_NONE; + a[(s + 2) % p] = LV_CHART_POINT_NONE; + a[(s + 2) % p] = LV_CHART_POINT_NONE; + + lv_chart_refresh(chart); +} + +/** + * Circular line chart with gap + */ +void lv_example_chart_9(void) +{ + /*Create a stacked_area_chart.obj*/ + lv_obj_t * chart = lv_chart_create(lv_scr_act()); + lv_chart_set_update_mode(chart, LV_CHART_UPDATE_MODE_CIRCULAR); + lv_obj_set_size(chart, 200, 150); + lv_obj_center(chart); + + lv_chart_set_point_count(chart, 30); + lv_chart_series_t * ser = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_RED), LV_CHART_AXIS_PRIMARY_Y); + /*Prefill with data*/ + uint32_t i; + for(i = 0; i < 30; i++) { + lv_chart_set_next_value(chart, ser, lv_rand(10, 90)); + } + + lv_timer_create(add_data, 300, chart); + +} + +#endif diff --git a/examples/widgets/lv_example_widgets.h b/examples/widgets/lv_example_widgets.h index b7e0a111b..cd55e6231 100644 --- a/examples/widgets/lv_example_widgets.h +++ b/examples/widgets/lv_example_widgets.h @@ -58,6 +58,7 @@ void lv_example_chart_5(void); void lv_example_chart_6(void); void lv_example_chart_7(void); void lv_example_chart_8(void); +void lv_example_chart_9(void); void lv_example_checkbox_1(void); void lv_example_checkbox_2(void);