Skip to content
API 风格:

Chart 统计图 ​

LhChart 是零第三方依赖的自研统计图组件:折线、柱状、面积、饼、环五种类型, 底层为框架无关的纯 SVG 渲染引擎(@lh-ui/share/core/chart),序列色走 --lh-chart-* CSS 变量, 与明暗主题、ConfigProvider 组件级覆盖天然统一。体积约为 ECharts 按需方案的 6%。

基础用法(折线图) ​

折线图 type=「line」:类目标签 + 多系列
vue
<script setup lang="ts">
import { LhChart } from '@lh-ui/vue3'
</script>

<template>
  <LhChart
    type="line"
    :data="{
      labels: ['一月', '二月', '三月', '四月', '五月', '六月'],
      series: [
        { name: '营收', data: [30, 60, 45, 80, 65, 95] },
        { name: '成本', data: [20, 40, 35, 50, 45, 60] },
      ],
    }"
  />
</template>
vue
<script>
export default {}
</script>

<template>
  <LhChart
    type="line"
    :data="{
      labels: ['一月', '二月', '三月', '四月', '五月', '六月'],
      series: [
        { name: '营收', data: [30, 60, 45, 80, 65, 95] },
        { name: '成本', data: [20, 40, 35, 50, 45, 60] },
      ],
    }"
  />
</template>

柱状图与堆叠 ​

柱状图 type=「bar」:stack 开启堆叠、round 开启圆角柱
vue
<script setup lang="ts">
import { LhChart } from '@lh-ui/vue3'
</script>

<template>
  <LhChart
    type="bar"
    stack
    round
    :data="{
      labels: ['Q1', 'Q2', 'Q3', 'Q4'],
      series: [
        { name: '华东', data: [120, 150, 140, 180] },
        { name: '华北', data: [80, 95, 110, 130] },
      ],
    }"
  />
</template>
vue
<script>
export default {}
</script>

<template>
  <LhChart
    type="bar"
    stack
    round
    :data="{
      labels: ['Q1', 'Q2', 'Q3', 'Q4'],
      series: [
        { name: '华东', data: [120, 150, 140, 180] },
        { name: '华北', data: [80, 95, 110, 130] },
      ],
    }"
  />
</template>

面积图与平滑曲线 ​

面积图 type=「area」+ smooth:单调三次贝塞尔,防过冲
vue
<script setup lang="ts">
import { LhChart } from '@lh-ui/vue3'
</script>

<template>
  <LhChart
    type="area"
    smooth
    :data="{
      labels: ['周一', '周二', '周三', '周四', '周五'],
      series: [{ name: '活跃用户', data: [820, 932, 901, 1034, 1290] }],
    }"
  />
</template>
vue
<script>
export default {}
</script>

<template>
  <LhChart
    type="area"
    smooth
    :data="{
      labels: ['周一', '周二', '周三', '周四', '周五'],
      series: [{ name: '活跃用户', data: [820, 932, 901, 1034, 1290] }],
    }"
  />
</template>

饼图与环图 ​

饼图 / 环图 type=「pie」「donut」:取首系列,扇区占比可点图例隐藏
vue
<script setup lang="ts">
import { LhChart } from '@lh-ui/vue3'
</script>

<template>
  <LhChart
    type="donut"
    :data="{
      labels: ['直接访问', '搜索引擎', '外部链接', '其他'],
      series: [{ name: '访问来源', data: [335, 310, 234, 135] }],
    }"
  />
</template>
vue
<script>
export default {}
</script>

<template>
  <LhChart
    type="donut"
    :data="{
      labels: ['直接访问', '搜索引擎', '外部链接', '其他'],
      series: [{ name: '访问来源', data: [335, 310, 234, 135] }],
    }"
  />
</template>

空态与加载 ​

loading 加载遮罩;空数据渲染空态占位
vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhChart } from '@lh-ui/vue3'

const loading = ref(true)
const data = ref({ labels: [], series: [] })
</script>

<template>
  <LhChart loading :data="data" />
</template>
vue
<script>
export default {
  data() {
    return { loading: true, data: { labels: [], series: [] } }
  },
}
</script>

<template>
  <LhChart :loading="loading" :data="data" />
</template>

API ​

Props ​

属性说明类型默认值
type图表类型'line' | 'bar' | 'area' | 'pie' | 'donut''line'
data图表数据(类目标签 + 系列;pie / donut 取首个系列)LhChartData—
height画布高度 pxnumber320
smooth折线 / 面积平滑(单调贝塞尔,防过冲)booleanfalse
stack堆叠(仅 bar / area;负值按 0 计入)booleanfalse
round柱圆角(仅 bar)booleanfalse
legend图例(点击可显隐系列)booleantrue
tooltip悬浮提示层(类目吸附)booleantrue
grid网格线与坐标轴标签booleantrue
animated入场动画(仅首次渲染)booleantrue
precision数值小数位上限number2
innerRadius饼图内半径比例(donut 默认 0.6)number0
loading加载遮罩booleanfalse
ariaLabel无障碍可达名称(缺省由数据兜底)string—
themeVars组件级主题变量(键自动加 --lh- 前缀)Record<string, string>—
sxsx 快速布局属性LhSxProps—

Events ​

事件名说明回调参数
legend-change图例点击切换系列显隐时触发(legend: { name: string; hidden: boolean }[])

data 数据结构 ​

ts
interface LhChartData {
  /** 类目标签;缺失时按索引兜底 */
  labels?: string[]
  /** 数据序列;pie / donut 取首个系列 */
  series: { name: string; data: number[]; color?: string }[]
}

无障碍 ​

  • 根节点 role="img" + aria-label(ariaLabel 缺省时由图表类型 + 系列名兜底)
  • 内置视觉隐藏的原始数据表(.lh-chart__sr-table),屏幕阅读器可直接读取全部数值
  • 图例项为原生 button + aria-pressed,键盘可操作
  • 系统开启「减弱动态效果」时自动跳过入场动画(prefers-reduced-motion)