LVGL V8.2.0之Axis ticks and labels with scrolling
and with LVGL axis
2023-09-14 09:11:17 时间
绘制函数回调
static void draw_event_cb(lv_event_t* e)
{
lv_obj_draw_part_dsc_t* dsc = lv_event_get_draw_part_dsc(e); //获取事件对象绘制描述符指针
if (!lv_obj_draw_part_check_type(dsc, &lv_chart_class, LV_CHART_DRAW_PART_TICK_LABEL)) return; // LV_CHART_DRAW_PART_TICK_LABEL部分不绘制
if (dsc->id == LV_CHART_AXIS_PRIMARY_X && dsc->text) {
const char* month[] = { "Jan", "Febr", "March", "Apr", "May", "Jun", "July","Aug", "Sept", "Oct", "Nov", "Dec" };
lv_snprintf(dsc->text, dsc->text_length, "%s", month[dsc->value]); //格式化显示内容到dsc->text指向的内存
}
}
创建CHART
static void lv_example_chart_3(void)
{
/*Create a chart*/
lv_obj_t* chart;
chart = lv_chart_create(lv_scr_act()); //创建CHART对象
lv_obj_set_size(chart, 200, 150); // 设置大小
lv_obj_center(chart); //居中显示
lv_chart_set_type(chart, LV_CHART_TYPE_BAR); //设置CHART为BAR类型
lv_chart_set_range(chart, LV_CHART_AXIS_PRIMARY_Y, 0, 100); //设置y主轴范围为0~100
lv_chart_set_range(chart, LV_CHART_AXIS_SECONDARY_Y, 0, 400);//设置y第2轴范围为0~400
lv_chart_set_point_count(chart, 12); // 设置12个BAR形点数
lv_obj_add_event_cb(chart, draw_event_cb, LV_EVENT_DRAW_PART_BEGIN, NULL);//添加LV_EVENT_DRAW_PART_BEGIN绘制事件
/*Add ticks and label to every axis*/
lv_chart_set_axis_tick(chart, LV_CHART_AXIS_PRIMARY_X, 10, 5, 12, 3, true, 40);
lv_chart_set_axis_tick(chart, LV_CHART_AXIS_PRIMARY_Y, 10, 5, 6, 2, true, 50);
lv_chart_set_axis_tick(chart, LV_CHART_AXIS_SECONDARY_Y, 10, 5, 3, 4, true, 50);
/*Zoom in a little in X*/
lv_chart_set_zoom_x(chart, 800); // x方向放大800/256倍
/*添加2条数据线*/
lv_chart_series_t* ser1 = lv_chart_add_series(chart, lv_palette_lighten(LV_PALETTE_GREEN, 2), LV_CHART_AXIS_PRIMARY_Y);
lv_chart_series_t* ser2 = lv_chart_add_series(chart, lv_palette_darken(LV_PALETTE_GREEN, 2),
LV_CHART_AXIS_SECONDARY_Y);
/*设置数据到ser1'*/
lv_chart_set_next_value(chart, ser1, 31);
lv_chart_set_next_value(chart, ser1, 66);
lv_chart_set_next_value(chart, ser1, 10);
lv_chart_set_next_value(chart, ser1, 89);
lv_chart_set_next_value(chart, ser1, 63);
lv_chart_set_next_value(chart, ser1, 56);
lv_chart_set_next_value(chart, ser1, 32);
lv_chart_set_next_value(chart, ser1, 35);
lv_chart_set_next_value(chart, ser1, 57);
lv_chart_set_next_value(chart, ser1, 85);
lv_chart_set_next_value(chart, ser1, 22);
lv_chart_set_next_value(chart, ser1, 58);
lv_coord_t* ser2_array = lv_chart_get_y_array(chart, ser2);
/*设置数据到ser2'*/
ser2_array[0] = 92;
ser2_array[1] = 71;
ser2_array[2] = 61;
ser2_array[3] = 15;
ser2_array[4] = 21;
ser2_array[5] = 35;
ser2_array[6] = 35;
ser2_array[7] = 58;
ser2_array[8] = 31;
ser2_array[9] = 53;
ser2_array[10] = 33;
ser2_array[11] = 73;
lv_chart_refresh(chart); /*刷新显示*/
}
运行效果图
相关文章
- Further Adventures With CAS Instructions And Micro Benchmarking
- Building the Unstructured Data Warehouse: Architecture, Analysis, and Design
- [Javascript] Create an Async Generator and Loop Through Generated Promises with "For Await Of" Loops
- [Docker] Linking Node.js and MongoDB Containers
- [React] Persist Form Data in React and Formik with formik-persist
- [RxJS] AsyncSubject and ReplaySubject - Learn the Differences
- [Vue + TS] Use Dependency Injection in Vue Using @Inject and @Provide Decorators with TypeScript
- [Javascript] Format console.log with CSS and String Template Tags
- [TypeScript] Configuring TypeScript Which Files to Compile with "Files" and "OutDir"
- 11.2 Job Seperation causes WARNINGS and ORA-15025 ORA-27041 With Certain Users (文档 ID 1317692.1)
- [Algorithms] Divide and Recurse Over an Array with Merge Sort in JavaScript
- [Tools] Convert SVG to a PDF in Node with PDFKit and SVG.js
- Fiori Elements - OData metadata response and annotation merge
- Atitit Gaussian Blur 高斯模糊 的原理and实现and 用途
- atitit.html5动画特效----打水漂 ducks_and_drakes
- 【Codeforces 639A】Bear and Displayed Friends
- 【Henu ACM Round#16 B】 Bear and Colors
- leetcode - Construct Binary Tree from Inorder and Postorder Traversal
- LVGL V8.2.0之Axis ticks and labels with scrolling
- 【文献学习】1 Power of Deep Learning for Channel Estimation and Signal Detection in OFDM
- How to working with dates and times?