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
| Prop | Description | Type | Default |
|---|---|---|---|
| type | Chart type | 'line' | 'bar' | 'area' | 'pie' | 'donut' | 'line' |
| data | Chart data (category labels + series; pie / donut take the first series) | LhChartData | — |
| height | Canvas height in px | number | 320 |
| smooth | Line / area smoothing (monotone Bézier, overshoot-free) | boolean | false |
| stack | Stacking (bar / area only; negative values count as 0) | boolean | false |
| round | Rounded bars (bar only) | boolean | false |
| legend | Legend (click to show/hide a series) | boolean | true |
| tooltip | Hover tooltip (snaps to category) | boolean | true |
| grid | Grid lines and axis labels | boolean | true |
| animated | Enter animation (first render only) | boolean | true |
| precision | Max decimal places of values | number | 2 |
| innerRadius | Inner radius ratio of the pie (donut defaults to 0.6) | number | 0 |
| loading | Loading mask | boolean | false |
| ariaLabel | Accessible name (falls back to data when missing) | string | — |
| themeVars | Component-level theme variables (keys get the --lh- prefix automatically) | Record<string, string> | — |
| sx | sx quick-layout props | LhSxProps | — |
Events
| Event | Description | Callback |
|---|---|---|
| legend-change | Fired 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(whenariaLabelis 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 witharia-pressed, operable by keyboard - The enter animation is skipped automatically when the system requests reduced motion (
prefers-reduced-motion)

