Skip to content

Chart 统计图 ​

五型统计图(bar 柱状 / line 折线 / area 面积 / pie 饼图 / donut 环形)。几何、刻度、 命中检测与格式化消费 @lh-ui/share/core/chart;画布走 <canvas type="2d">(几何 path 字符串经 Path2D 直接消费,与 web 端 SVG 同源),主题色经隐藏探针视图解析 --lh-chart-* 令牌(明暗主题自动跟随)。

基础用法 ​

vue
<template>
  <lh-chart :data="data" type="line" />
</template>

<script setup lang="ts">
import { ref } from 'vue'

const data = ref({
  labels: ['一月', '二月', '三月', '四月'],
  series: [{ name: '水墨', data: [12, 28, 22, 40] }],
})
</script>

饼图 / 环形图 ​

pie 的图例与命中语义为扇区(labels),bar/line/area 为系列。

vue
<template>
  <lh-chart :data="data" type="pie" />
  <lh-chart :data="data" type="donut" />
</template>

<script setup lang="ts">
import { ref } from 'vue'

const data = ref({
  labels: ['水墨', '丹青', '工笔', '写意'],
  series: [{ name: '占比', data: [45, 25, 18, 12] }],
})
</script>

柱状图(正负值与堆叠) ​

vue
<template>
  <lh-chart :data="data" type="bar" />
  <lh-chart :data="data" type="bar" stack />
</template>

图例显隐与触摸提示 ​

图例点击隐藏系列 / 扇区;触摸画布显示 tooltip,抬手触发 select 事件 (detail:label / seriesName / value / x / y)。

vue
<template>
  <lh-chart :data="data" type="line" @select="onSelect" />
</template>

Props ​

属性说明类型默认值
type图表类型'bar' | 'line' | 'area' | 'pie' | 'donut''line'
data数据(labels 类目 + series 序列)LhChartData{ series: [] }
height画布高度 px(宽度随容器 100%)number320
animated入场动画booleantrue
showLegend显示图例(可点击显隐)booleantrue
showTooltip触摸 tooltipbooleantrue
smooth折线平滑(line / area)booleanfalse
stack堆叠形态(bar / area)booleanfalse
innerRadiuspie 内半径比例(donut 缺省 0.6)number0
emptyText空数据态文案string语言包 chart.empty
customClass自定义类名(透传根节点)string—
sxsx 快速布局属性——

Events ​

事件说明回调参数
select触摸命中数据点(抬手提交)(detail: { label, seriesName, value, x, y })

无障碍 ​

  • 根元素 aria-role="img" + 可达名称(语言包 chart.ariaLabel)
  • 空数据态文案可达;图例为可点击视图,显隐状态由修饰类呈现

端内降级 ​

  • 柱体圆角令牌 --lh-chart-bar-radius v1 不参与 canvas 绘制(roundRect 基础库 支持度未实测),柱体直角渲染
  • 主题探针解析失败时回退与令牌同源的内置色板(LH_CHART_FALLBACK_COLORS)