lv_chart
图表控件由背景、水平垂直分割线、数据线组成
样式
/*Parts of the chart*/
enum {
LV_CHART_PART_BG = LV_OBJ_PART_MAIN,
LV_CHART_PART_SERIES_BG = _LV_OBJ_PART_VIRTUAL_LAST,
LV_CHART_PART_SERIES,
LV_CHART_PART_CURSOR
};
例子
void lv_ex_chart_2(void)
{
/*Create a chart*/
lv_obj_t * chart;
chart = lv_chart_create(lv_scr_act(), NULL);
lv_obj_set_size(chart, 200, 150);
lv_obj_align(chart, NULL, LV_ALIGN_CENTER, 0, 0);
lv_chart_set_type(chart, LV_CHART_TYPE_LINE); /*Show lines and points too*/
lv_chart_set_div_line_count(chart,3,5);//设置水平垂直分割线条数,默认3,5
lv_chart_set_range(chart, 0, 100);//设置y轴数值范围,默认0-100
#if 0
//这里设置标题,lv_chart_set_margin设置刻度区域高度新版没有
lv_chart_set_x_tick_texts(chart,"1\n2\n3\n4\n5",3, LV_CHART_AXIS_DRAW_LAST_TICK);
lv_chart_set_x_tick_length(chart, 10, 3);
lv_chart_set_margin(chart, 30);
#endif
/*Add a faded are effect 从上往下渐变效果*/
lv_obj_set_style_local_bg_opa(chart, LV_CHART_PART_SERIES, LV_STATE_DEFAULT, LV_OPA_50); /*Max. opa.*/
lv_obj_set_style_local_bg_grad_dir(chart, LV_CHART_PART_SERIES, LV_STATE_DEFAULT, LV_GRAD_DIR_VER);
lv_obj_set_style_local_bg_main_stop(chart, LV_CHART_PART_SERIES, LV_STATE_DEFAULT, 255); /*Max opa on the top*/
lv_obj_set_style_local_bg_grad_stop(chart, LV_CHART_PART_SERIES, LV_STATE_DEFAULT, 0); /*Transparent on the bottom*/
/*Add two data series添加2条数据线*/
lv_chart_series_t * ser1 = lv_chart_add_series(chart, LV_COLOR_RED);
lv_chart_series_t * ser2 = lv_chart_add_series(chart, LV_COLOR_GREEN);
/*Set the next points on 'ser1'*/
lv_chart_set_next(chart, ser1, 31);
lv_chart_set_next(chart, ser1, 66);
lv_chart_set_next(chart, ser1, 10);
lv_chart_set_next(chart, ser1, 89);
lv_chart_set_next(chart, ser1, 63);
lv_chart_set_next(chart, ser1, 56);
lv_chart_set_next(chart, ser1, 32);
lv_chart_set_next(chart, ser1, 35);
lv_chart_set_next(chart, ser1, 57);
lv_chart_set_next(chart, ser1, 85);
/*Directly set points on 'ser2'*/
ser2->points[0] = 92;
ser2->points[1] = 71;
ser2->points[2] = 61;
ser2->points[3] = 15;
ser2->points[4] = 21;
ser2->points[5] = 35;
ser2->points[6] = 35;
ser2->points[7] = 58;
ser2->points[8] = 31;
ser2->points[9] = 53;
lv_chart_refresh(chart); /*Required after direct set*/
}