柱状图
用途
ui.widgets.chart 是桌面阅读统计用的柱状图。锁屏上的同类图元在 features.lockscreen.components.chart,不要混用。纵轴刻度把秒格式化成「N 分钟」或「N 小时」。
主要参数
Chart.bars(opts):
| 字段 | 作用 |
|---|---|
points | { { value 或 seconds, label } }。也可分传 values + labels |
value_key / label_key | 从点对象里取字段,缺省 value / label |
width / height | 物理像素。高度缺省 Theme.px(80) |
gap | 柱间距,缺省 space.xs |
show_labels | false 时不画柱下标签 |
Chart.axisLabel(seconds) 把秒转成刻度文案,一般不必直接调。
和三种风格的差异
柱体填充走强调色(彩色开启后即主题色),坐标轴文字用 muted。高对比下线条更黑。
示例
local Theme = require("ui.themes")local Chart = require("ui.widgets.chart")local bars = Chart.bars({ width = w, height = Theme.px(120), points = { { seconds = 1800, label = _("一") }, { seconds = 3600, label = _("二") }, { seconds = 900, label = _("三") }, },})本文已加密,请输入访问密码