Skip to content
API 风格:

Chart ​

LhChart is a self-built chart component with zero third-party dependencies: five types — line, bar, area, pie and donut — powered by a framework-agnostic pure SVG rendering engine (@lh-ui/share/core/chart). Series colors go through the --lh-chart-* CSS variables, naturally unified with light/dark themes and ConfigProvider component-level overrides. Its size is roughly 6% of an on-demand ECharts setup.

Basic Usage (line chart) ​

Line chart type=「line」: category labels + multiple series
vue
<script setup lang="ts">
import { LhChart } from '@lh-ui/vue3'
</script>

<template>
  <LhChart
    type="line"
    :data="{
      labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
      series: [
        { name: 'Revenue', data: [30, 60, 45, 80, 65, 95] },
        { name: 'Cost', data: [20, 40, 35, 50, 45, 60] },
      ],
    }"
  />
</template>
vue
<script>
export default {}
</script>

<template>
  <LhChart
    type="line"
    :data="{
      labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
      series: [
        { name: 'Revenue', data: [30, 60, 45, 80, 65, 95] },
        { name: 'Cost', data: [20, 40, 35, 50, 45, 60] },
      ],
    }"
  />
</template>

Bar chart and stacking ​

Bar chart type=「bar」: stack enables stacking, round enables rounded bars
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: 'East China', data: [120, 150, 140, 180] },
        { name: 'North China', 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: 'East China', data: [120, 150, 140, 180] },
        { name: 'North China', data: [80, 95, 110, 130] },
      ],
    }"
  />
</template>

Area chart and smooth curves ​

Area chart type=「area」+ smooth: monotone cubic Bézier, overshoot-free
vue
<script setup lang="ts">
import { LhChart } from '@lh-ui/vue3'
</script>

<template>
  <LhChart
    type="area"
    smooth
    :data="{
      labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'],
      series: [{ name: 'Active users', data: [820, 932, 901, 1034, 1290] }],
    }"
  />
</template>
vue
<script>
export default {}
</script>

<template>
  <LhChart
    type="area"
    smooth
    :data="{
      labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'],
      series: [{ name: 'Active users', data: [820, 932, 901, 1034, 1290] }],
    }"
  />
</template>

Pie and donut charts ​

Pie / donut type=「pie」「donut」: takes the first series; click a legend item to hide its slice
vue
<script setup lang="ts">
import { LhChart } from '@lh-ui/vue3'
</script>

<template>
  <LhChart
    type="donut"
    :data="{
      labels: ['Direct visits', 'Search engines', 'External links', 'Other'],
      series: [{ name: 'Traffic source', data: [335, 310, 234, 135] }],
    }"
  />
</template>
vue
<script>
export default {}
</script>

<template>
  <LhChart
    type="donut"
    :data="{
      labels: ['Direct visits', 'Search engines', 'External links', 'Other'],
      series: [{ name: 'Traffic source', data: [335, 310, 234, 135] }],
    }"
  />
</template>

Empty and loading states ​

loading loading mask; empty data renders an empty-state placeholder
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 ​

PropDescriptionTypeDefault
typeChart type'line' | 'bar' | 'area' | 'pie' | 'donut''line'
dataChart data (category labels + series; pie / donut take the first series)LhChartData—
heightCanvas height in pxnumber320
smoothLine / area smoothing (monotone Bézier, overshoot-free)booleanfalse
stackStacking (bar / area only; negative values count as 0)booleanfalse
roundRounded bars (bar only)booleanfalse
legendLegend (click to show/hide a series)booleantrue
tooltipHover tooltip (snaps to category)booleantrue
gridGrid lines and axis labelsbooleantrue
animatedEnter animation (first render only)booleantrue
precisionMax decimal places of valuesnumber2
innerRadiusInner radius ratio of the pie (donut defaults to 0.6)number0
loadingLoading maskbooleanfalse
ariaLabelAccessible name (falls back to data when missing)string—
themeVarsComponent-level theme variables (keys get the --lh- prefix automatically)Record<string, string>—
sxsx quick-layout propsLhSxProps—

Events ​

EventDescriptionCallback
legend-changeFired when a legend item toggles a series' visibility(legend: { name: string; hidden: boolean }[])

data structure ​

ts
interface LhChartData {
  /** Category labels; falls back to index when missing */
  labels?: string[]
  /** Data series; pie / donut take the first series */
  series: { name: string; data: number[]; color?: string }[]
}

Accessibility ​

  • The root node has role="img" + aria-label (when ariaLabel is missing, falls back to chart type + series names)
  • A visually hidden raw-data table (.lh-chart__sr-table) is built in, so screen readers can read every value directly
  • Legend items are native buttons with aria-pressed, operable by keyboard
  • The enter animation is skipped automatically when the system requests reduced motion (prefers-reduced-motion)

Beauty of tradition, foundation of code