数据定型定义

/* A struct is used to keep track of the series list because later we need to draw to the series in the reverse order to which they were initialised. */
typedef struct {lv_obj_t* obj;lv_chart_series_t* series_list[3];
} stacked_area_chart_t;

定义变量

static stacked_area_chart_t stacked_area_chart;

事件处理函数

/**
* Callback which draws the blocks of colour under the lines
**/
static void draw_event_cb(lv_event_t* e)
{lv_obj_t* obj = lv_event_get_target(e); // 获取产生事件的对象/*Add the faded area before the lines are drawn*/lv_obj_draw_part_dsc_t* dsc = lv_event_get_draw_part_dsc(e); //获取事件绘制描述符if (dsc->part == LV_PART_ITEMS) { //仅对LV_PART_ITEMS处理if (!dsc->p1 || !dsc->p2)  //空指针不处理return;/*Add a line mask that keeps the area below the line*/lv_draw_mask_line_param_t line_mask_param;lv_draw_mask_line_points_init(&line_mask_param, dsc->p1->x, dsc->p1->y, dsc->p2->x, dsc->p2->y,LV_DRAW_MASK_LINE_SIDE_BOTTOM); // 初时化线条mask参数int16_t line_mask_id = lv_draw_mask_add(&line_mask_param, NULL); //添加mask/*Draw a rectangle that will be affected by the mask*/lv_draw_rect_dsc_t draw_rect_dsc;lv_draw_rect_dsc_init(&draw_rect_dsc);draw_rect_dsc.bg_opa = LV_OPA_COVER;  //透明度为覆盖draw_rect_dsc.bg_color = dsc->line_dsc->color; //背景色和线条同色lv_area_t a;a.x1 = dsc->p1->x;a.x2 = dsc->p2->x;a.y1 = LV_MIN(dsc->p1->y, dsc->p2->y); //取最小值a.y2 = obj->coords.y2 -13; /* -13 cuts off where the rectangle draws over the chart margin.Without this an area of 0 doesn't look like 0 */lv_draw_rect(dsc->draw_ctx, &draw_rect_dsc, &a); //绘制矩形区域/*Remove the mask*/lv_draw_mask_free_param(&line_mask_param); //移除mask paramlv_draw_mask_remove_id(line_mask_id); //移除mask id}
}

四舍五入处理

/**
* Helper function to round a fixed point number
**/
static int32_t round_fixed_point(int32_t n, int8_t shift)
{/* Create a bitmask to isolates the decimal part of the fixed point number */int32_t mask = 1;for (int32_t bit_pos = 0; bit_pos < shift; bit_pos++) {mask = (mask << 1) + 1;}int32_t decimal_part = n & mask;/* Get 0.5 as fixed point */int32_t rounding_boundary = 1 << (shift - 1);/* Return either the integer part of n or the integer part + 1 */return (decimal_part < rounding_boundary) ? (n & ~mask) : ((n >> shift) + 1) << shift;
}

创建Stacked area chart

/**
* Stacked area chart
*/
static void lv_example_chart_8(void)
{/*Create a stacked_area_chart.obj*/stacked_area_chart.obj = lv_chart_create(lv_scr_act()); //创建CHART对象lv_obj_set_size(stacked_area_chart.obj, 200, 150); //设置大小lv_obj_center(stacked_area_chart.obj); //居中显示lv_chart_set_type(stacked_area_chart.obj, LV_CHART_TYPE_LINE);//CHART类型为LV_CHART_TYPE_LINElv_chart_set_div_line_count(stacked_area_chart.obj, 5, 7); //设置分割线为5x7lv_obj_add_event_cb(stacked_area_chart.obj, draw_event_cb, LV_EVENT_DRAW_PART_BEGIN, NULL); // 添加LV_EVENT_DRAW_PART_BEGIN事件/* Set range to 0 to 100 for percentages. Draw ticks */lv_chart_set_range(stacked_area_chart.obj, LV_CHART_AXIS_PRIMARY_Y, 0, 100);//设置主Y轴范围为0~100lv_chart_set_axis_tick(stacked_area_chart.obj, LV_CHART_AXIS_PRIMARY_Y, 3, 0, 5, 1, true, 30); //设置Y轴tick/*Set point size to 0 so the lines are smooth */lv_obj_set_style_size(stacked_area_chart.obj, 0, LV_PART_INDICATOR); //LV_PART_INDICATOR对应的size设成0/*Add some data series*/stacked_area_chart.series_list[0] = lv_chart_add_series(stacked_area_chart.obj, lv_palette_main(LV_PALETTE_RED), LV_CHART_AXIS_PRIMARY_Y); //第一条红色线添加到CHARTstacked_area_chart.series_list[1] = lv_chart_add_series(stacked_area_chart.obj, lv_palette_main(LV_PALETTE_BLUE),LV_CHART_AXIS_PRIMARY_Y);  //第二条蓝色线添加到CHARTstacked_area_chart.series_list[2] = lv_chart_add_series(stacked_area_chart.obj,lv_palette_main(LV_PALETTE_GREEN),LV_CHART_AXIS_PRIMARY_Y); //第三条绿色线添加到CHARTfor (int point = 0; point < 10; point++) {/* Make some random data */uint32_t vals[3] = { lv_rand(10, 20), lv_rand(20, 30), lv_rand(20, 30) };int8_t fixed_point_shift = 5;uint32_t total = vals[0] + vals[1] + vals[2];uint32_t draw_heights[3];uint32_t int_sum = 0;uint32_t decimal_sum = 0;/* Fixed point cascade rounding ensures percentages add to 100 */for (int32_t series_index = 0; series_index < 3; series_index++) { //三条线设置数据decimal_sum += (((vals[series_index] * 100) << fixed_point_shift) / total);int_sum += (vals[series_index] * 100) / total;int32_t modifier = (round_fixed_point(decimal_sum, fixed_point_shift) >> fixed_point_shift) - int_sum;/* The draw heights are equal to the percentage of the total each value is + the cumulative sum of the previous percentages.The accumulation is how the values get "stacked" */draw_heights[series_index] = int_sum + modifier;/* Draw to the series in the reverse order to which they were initialised.Without this the higher values will draw on top of the lower ones.This is because the Z-height of a series matches the order it was initialised */lv_chart_set_next_value(stacked_area_chart.obj, stacked_area_chart.series_list[3 - series_index - 1],draw_heights[series_index]);}}lv_chart_refresh(stacked_area_chart.obj); //刷新显示
}

显示效果图

LVGL 8.2.0 Stacked area chart相关推荐

  1. R绘制堆叠的密度图(Stacked Area Chart)

    R绘制堆叠的密度图(Stacked Area Chart) 堆叠面积图(Stacked Area Chart)就像折线图一样,只是图像的面积区域都是彩色的.这种可视化方式通常在以下情况下使用. 我们想 ...

  2. Python使用matplotlib可视化时间序列堆叠的面积图、堆叠面积图给出了多个时间序列的贡献程度的可视化表示,以便于相互比较(Stacked Area Chart)

    Python使用matplotlib可视化时间序列堆叠的面积图.堆叠面积图给出了多个时间序列的贡献程度的可视化表示,以便于相互比较(Stacked Area Chart) 目录

  3. R语言ggplot2可视化:绘制堆叠的密度图(Stacked Area Chart)

    R语言ggplot2可视化:绘制堆叠的密度图(Stacked Area Chart) 目录 R语言ggplot2可视化:绘制堆叠的密度图(Stacked Area Chart) #仿真数据 #绘制堆叠 ...

  4. LVGL 8.2.0 CHART显示ECG数据

    ECG数据表格 /* Source: https://github.com/ankur219/ECG-Arrhythmia-classification/blob/642230149583adfae1 ...

  5. 26.27.28.29.极区图(南丁格尔玫瑰图)、维恩图 (Venn diagram)、面状图(Area chart)、树地图

    26.极区图(南丁格尔玫瑰图) 27.维恩图 (Venn diagram) 28.面状图(Area chart) 29.树地图 26.极区图(南丁格尔玫瑰图) 极区图(又名南丁格尔玫瑰图)呈放射延伸状 ...

  6. 16、17、18_使用gridspec定义多子图,条形图(Bar plots),分组条形图,堆叠条形图(Stacked bar chart),饼图(Pie plots),甜甜圈图,嵌套饼图

    16.使用gridspec定义多子图 16.1.图标题 17.条形图(Bar plots) 17.1.分组条形图 17.2.堆叠条形图(Stacked bar chart) 18.饼图(Pie plo ...

  7. 数据可视化【六】Line Chart Area Chart

    Line Chart vizhub代码: https://vizhub.com/Edward-Elric233/094396fc7a164c828a4a8c2e13045308 实现效果: 这里先使用 ...

  8. Python使用matplotlib可视化面积图(Area Chart)、通过给坐标轴和曲线之间的区域着色可视化面积图、在面积图的指定区域添加箭头和数值标签

    Python使用matplotlib可视化面积图(Area Chart).通过给坐标轴和曲线之间的区域着色可视化面积图.在面积图的指定区域添加箭头和数值标签 目录

  9. R语言可视化面积图(area chart)移除轴标签与实际图形之间的空白区域实战:默认的面积图、移除轴标签与实际图形之间的空白区域

    R语言可视化面积图(area chart)移除轴标签与实际图形之间的空白区域实战:默认的面积图.移除轴标签与实际图形之间的空白区域 目录

最新文章

  1. python查看包的安装路径_查看python包的安装路径,检查安装路径设置。Python包的Python来自,从中,检测...
  2. 第 3 章 镜像 - 014 - 镜像的缓存特性
  3. c语言中的文件类型只有文本文件一种,C语言中的文件类型只有哪两种_后端开发...
  4. leetcode算法题--机器人的运动范围
  5. 计算机网络技术教法改革方案,计算机网络实验论文,关于“计算机网络”教学改革相关参考文献资料-免费论文范文...
  6. 如何使用 Nginx 优雅地限流?
  7. 电脑知识:BIOS和UEFI的对比介绍!
  8. 基于微信小程序的用户列表点赞功能
  9. L1-052 2018我们要赢-PAT团体程序设计天梯赛GPLT
  10. rollback 最后判断成功_最后4天!这些你知道吗?
  11. java 实例化xpath_Java XPath示例教程
  12. Python字符串格式()
  13. 洛谷P1461 海明码 Hamming Codes
  14. 记录红米k40解BL、Root、装XPOSED
  15. Android adb shell启动应用程序的方法
  16. win7如何添加开机启动项
  17. 谷歌高级搜索技巧之高级语法查询指令
  18. 2019西安交通大学计算机复试,西安交通大学2019考研复试分数线多少分 各科基本分数线一览...
  19. 海思AI芯片(35xx):板端运行报错
  20. Sliced Sprite

热门文章

  1. WindowsMedia/FormWMP.cs
  2. 图学习中的链路预测任务(持续更新ing...)
  3. 4. 存储过程 · sql编程
  4. java做服务端,FLASH做客户端交互总结
  5. CDN服务及如何获取CDN服务背后的真实IP
  6. Java项目:游戏点评系统(java+SSM+JSP+JavaScript+mysql)
  7. Python实现AES中ECB模式pkcs5padding填充加密/解密(需要加密文档中可以有中文)
  8. PROTEUS中的复位电路
  9. 深度学习与计算机视觉-6章 Python-OpenCV
  10. Unity 粒子 基础