feat(chart) add scatter chart example
This commit is contained in:
59
examples/widgets/chart/lv_example_chart_7.c
Normal file
59
examples/widgets/chart/lv_example_chart_7.c
Normal file
@@ -0,0 +1,59 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_CHART && LV_BUILD_EXAMPLES
|
||||
|
||||
static void draw_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_obj_draw_part_dsc_t * dsc = lv_event_get_draw_part_dsc(e);
|
||||
if(dsc->part == LV_PART_ITEMS) {
|
||||
lv_obj_t * obj = lv_event_get_target(e);
|
||||
uint32_t cnt = lv_chart_get_point_count(obj);
|
||||
/*Make older value more transparent*/
|
||||
dsc->rect_dsc->bg_opa = (LV_OPA_COVER * dsc->id) / (cnt - 1);
|
||||
|
||||
/*Make smaller values blue, higher values red*/
|
||||
dsc->rect_dsc->bg_color = lv_color_mix(lv_palette_main(LV_PALETTE_RED),
|
||||
lv_palette_main(LV_PALETTE_BLUE),
|
||||
(dsc->value * LV_OPA_COVER) / 1000);
|
||||
}
|
||||
}
|
||||
|
||||
static void add_data(lv_timer_t * timer)
|
||||
{
|
||||
LV_UNUSED(timer);
|
||||
static uint32_t cnt = 0;
|
||||
lv_obj_t * chart = timer->user_data;
|
||||
lv_chart_set_next_value2(chart, lv_chart_get_series_next(chart, NULL), lv_rand(-100,100), lv_rand(0,1000));
|
||||
}
|
||||
|
||||
/**
|
||||
* A scatter chart
|
||||
*/
|
||||
void lv_example_chart_7(void)
|
||||
{
|
||||
lv_obj_t * chart = lv_chart_create(lv_scr_act());
|
||||
lv_obj_set_size(chart, 200, 150);
|
||||
lv_obj_align(chart, LV_ALIGN_CENTER, 0, -0);
|
||||
lv_obj_add_event_cb(chart, draw_event_cb, LV_EVENT_DRAW_PART_BEGIN, NULL);
|
||||
lv_obj_set_style_line_width(chart, 0, LV_PART_ITEMS);
|
||||
|
||||
lv_chart_set_type(chart, LV_CHART_TYPE_SCATTER);
|
||||
|
||||
lv_chart_set_axis_tick(chart, LV_CHART_AXIS_PRIMARY_X, 10, 5, 10, 1, true, 30);
|
||||
lv_chart_set_axis_tick(chart, LV_CHART_AXIS_PRIMARY_Y, 10, 5, 6, 5, true, 50);
|
||||
|
||||
lv_chart_set_range(chart, LV_CHART_AXIS_PRIMARY_X, -100, 100);
|
||||
lv_chart_set_range(chart, LV_CHART_AXIS_PRIMARY_Y, 0, 1000);
|
||||
|
||||
|
||||
lv_chart_set_point_count(chart, 50);
|
||||
|
||||
lv_chart_series_t * ser = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_RED), LV_CHART_AXIS_PRIMARY_Y);
|
||||
uint32_t i;
|
||||
for(i = 0; i < 50; i++) {
|
||||
lv_chart_set_next_value2(chart, ser, lv_rand(-100,100), lv_rand(0,1000));
|
||||
}
|
||||
|
||||
lv_timer_create(add_data, 100, chart);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -56,6 +56,7 @@ void lv_example_chart_3(void);
|
||||
void lv_example_chart_4(void);
|
||||
void lv_example_chart_5(void);
|
||||
void lv_example_chart_6(void);
|
||||
void lv_example_chart_7(void);
|
||||
|
||||
void lv_example_checkbox_1(void);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user