Guides

Charts

Draw area, line, bar, donut, pie and radial charts and sparklines that follow the theme.

components/ui/chart/BaseChart.vue
View in the demo

Charts run on Apache ECharts through vue-echarts, but your pages never touch the library. BaseChart takes simple props and buildChartOption() turns them into an ECharts option with the theme colours, the font and the accessibility settings.

A first chart

vue
<BaseChart
  type="area"
  :series="[
    { name: 'Desktop', data: [120, 132, 101, 134, 90, 230, 210] },
    { name: 'Mobile', data: [62, 82, 91, 84, 109, 110, 120] },
  ]"
  :categories="['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']"
  :aria-label="$t('analytics.usersByDay')"
/>

A single series can be a plain array: :series="[3, 7, 5]".

Props

Prop
Type
Default
Description
typearea | line | bar | donut | pie | radiallineThe kind of chart.
seriesChartSeries[] | number[][]The data. Each series has an optional name and its data.
categories(string | number)[][]X-axis labels, or slice names for donut, pie and radial.
stackedbooleanfalseStacks bars or areas.
horizontalbooleanfalseDraws bars horizontally.
markersbooleanfalseShows a dot on every point of line and area charts.
legendbooleanautoForces the legend on or off. By default it shows with more than one series.
value-format(value: number) => string—Formats axis labels and tooltips.
heightnumber | string280Height in pixels or any CSS length.
aria-labelstring—Describes the chart for screen readers.
loadingbooleanfalseShows BaseChartSkeleton instead of the chart.
optionsRecord<string, unknown>{}An ECharts option deep-merged on top, as an escape hatch.

Format values

vue
<script setup lang="ts">
const { currency } = useNumberFormat()

function money(value: number) {
  return currency(value, { maximumFractionDigits: 0, minimumFractionDigits: 0 })
}
</script>

<template>
  <BaseChart type="bar" :series="revenue" :categories="months" :value-format="money" />
</template>

Charts in cards

BaseChartCard wraps a chart in a card with a title and a description, and picks the type through a preset:

vue
<BaseChartCard
  :title="$t('finance.revenue')"
  :description="$t('finance.revenueText')"
  preset="stacked-bar"
  :series="series"
  :categories="months"
  :value-format="money"
/>

Presets are bar, stacked-bar, area, line, donut and pie. Use the #chart slot to render your own content.

Sparklines

BaseSparkline draws a small trend without axes with the same ECharts setup as BaseChart (3px line, the same end marker and hover guide). It loads on the client, so the server keeps an empty box of the same height:

vue
<BaseSparkline type="area" :series="[12, 18, 15, 22, 28]" :previous-series="[10, 14, 16, 15, 20]" />

It takes type (line, area, column), curve (smooth, straight), previous-series for the previous period, interactive for a hover pointer and label for screen readers.

Colours

Charts take every colour from useChartColors(): the series use the theme tokens chart-1 to chart-4, the previous period uses stone at 40 %, grids and axes use on-surface at 8 % and marker borders use surface. They change with dark mode and with the customizer's primary colour.

Never pass hex colours or info/warning to a chart, and keep single-series charts on the default chart-1.

Escape hatch

When you need an ECharts feature the props do not cover, pass it through options. It is merged over the generated option:

vue
<BaseChart type="line" :series="series" :categories="days" :options="{ yAxis: { min: 0, max: 100 } }" />

The library is loaded only when a chart appears on screen, inside ClientOnly, so it stays out of the main bundle. ECharts pieces are registered in utils/chart/echarts-setup.ts: add a new chart type or component there before using it in options.

License

Apache ECharts is licensed under Apache-2.0 and vue-echarts under MIT, both free for commercial use. Keep the license notice when you redistribute them.

© 2026 melsami UI.
Developer documentation for melsami UI.