Skip to main content

Chart

A lightweight chart component: five types (bar / line / area / pie / donut), pure SVG rendering with zero third-party dependencies. Series colors go through theme CSS variables, so light/dark and preset themes need no adaptation.

Comparison with mainstream solutions​

SolutionCharacteristicsOur choice
EChartsFeature-complete, mature ecosystemLarge bundle (still hundreds of KB minified), themes re-registered; not used
@ant-design/chartsDeclarative React wrapperHeavy G2 runtime, long dependency chain; not used
RechartsPure declarative React SVGWe adopt its "geometry as data" idea; we do not make every shape a React component — heavy reconciliation on large data. Our geometry is computed by pure functions and written directly to the SVG DOM
Chart.jsGood canvas performanceImperative API, weak a11y, disconnected from the CSS theme system; not used
Element Plus / Naive / ArcoNone ships chartsCharts are a blank spot in mainstream UI libraries; we treat it as a differentiator

Our strengths: geometry / ticks / hit-testing are all pure functions in @lh-ui/share/core/chart (shared and isomorphic across the Vue3 / Vue2 / mini-program builds; the single test suite lives in the share repo):

  • Zero-dependency pure SVG; the engine (types + logic + render) is 1659 lines; d3-style nice ticks (1/2/5×10ⁿ) and monotone cubic Bézier smoothing (Fritsch–Carlson, no overshoot)
  • Series colors inline var(--lh-chart-series-N) tokens: light/dark, the five preset themes and component-level themeVars cascade automatically through CSS; the engine never reads styles
  • ResizeObserver + rAF coalescing, redraw only on width change: tab switching and container show/hide adapt automatically, no manual resize
  • First-class a11y: role="img" accessible name plus a visually hidden raw-data table; prefers-reduced-motion disables animations automatically
  • Built-in empty and loading placeholders, with locale-driven (10 languages) reactive text

Basic usage​

Basic usage
Stack
Round corners
Smooth
import { LhChart } from '@lh-ui/react'

export default function Demo() {
const data = {
labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'],
series: [
{ name: 'Visits', data: [120, 200, 150, 80, 170] },
{ name: 'Orders', data: [40, 65, 50, 30, 60] },
],
}
return <LhChart type="line" data={data} />
}
Vue equivalent

type / data / height / smooth / stack / round / legend / tooltip / grid / animated / precision / innerRadius / loading match lh-ui-plus's LhChart props; the plus @legend-change event maps to the React onLegendChange callback prop.

Performance

data is an object reference in props and changes trigger a redraw. If the parent inlines a fresh data literal on every render, stabilize it with useMemo to avoid recomputing the chart on unrelated re-renders. Geometry runs in share-core pure functions; data updates fully rebuild the SVG (cheap for small data, cheaper than diffing).

pie / donut data

Pie and donut take the first visible series data, with labels as slice labels (a single-series share chart); use bar / line / area for multi-series data.

Accessibility

The chart root carries role="img"; a missing ariaLabel falls back to "series names + chart type". The raw data stays in the DOM as a visually hidden table so screen readers can read values item by item. For complex numbers pass an explicit ariaLabel.

Chart Props​

PropDescriptionTypeOptionsDefault
typeChart typeLhChartType'bar' | 'line' | 'area' | 'pie' | 'donut''line'
dataChart data (category labels + series; pie / donut use the first series)LhChartData——
heightCanvas height pxnumber—320
smoothLine / area smoothing (monotone cubic Bézier, no overshoot)boolean—false
stackStacked (bar / area only; negatives count as 0)boolean—false
roundRounded bar corners (bar only)boolean—false
legendShow legend (click to toggle a series)boolean—true
tooltipShow hover tooltipboolean—true
gridShow grid lines and axis labelsboolean—true
animatedEnter animation (first render only; data updates do not replay)boolean—true
precisionMax decimal places for valuesnumber—2
innerRadiusPie inner radius ratio (donut defaults to 0.6, pie to 0, by engine fallback)number0 - 0.95—
loadingLoading overlayboolean—false
ariaLabelAccessible name (falls back to data)string——
onLegendChangeLegend visibility change callback (uncontrolled; state lives in the engine)(legend: LhChartLegendItem[]) => void——
themeVarsComponent-level theme variables (override ConfigProvider and globals)Record<string, string>——
sxLayout shorthandSxProps——

Styles​

import '@lh-ui/react/theme.css'
import '@lh-ui/react/style/chart'

Series color tokens are --lh-chart-series-1 ~ -6, plus --lh-chart-grid-color / --lh-chart-axis-color / --lh-chart-tooltip-bg / --lh-chart-bar-radius and others; all can be overridden via themeVars.