Bar Chart

Documentation Index

Fetch the complete documentation index at: /llms.txt. Use this file to discover all available pages before exploring further.

Static, beautifully designed bar charts powered by Apache ECharts

Installation

npx shadcn-svelte@latest add https://evilcharts-sv.vercel.app/r/echarts-bar-chart.json

Usage

The ECharts bar chart is composable, sharing the LayerChart sibling’s API shape. <EChartsBarChart> is the container, and every part hangs off it as a compound member — <EChartsBarChart.Grid>, <EChartsBarChart.XAxis>, <EChartsBarChart.YAxis>, <EChartsBarChart.Legend>, <EChartsBarChart.Tooltip>, and one or more <EChartsBarChart.Bar> — so a single import gives you the whole chart. Each <Bar> carries its own variant, radius, glowing, bufferBar, and isClickable, so one chart can mix fill styles and make only some series interactive.

<script lang="ts">
	import {
		EChartsBarChart,
		type ChartConfig
	} from '$lib/components/evilcharts/charts/echarts-bar-chart/index.js';
</script>
<EChartsBarChart {data} config={chartConfig} stackType="default">
	<EChartsBarChart.Grid />
	<EChartsBarChart.XAxis dataKey="month" />
	<EChartsBarChart.Legend isClickable />
	<EChartsBarChart.Tooltip />
	<EChartsBarChart.Bar dataKey="desktop" variant="default" isClickable />
	<EChartsBarChart.Bar dataKey="mobile" variant="hatched" isClickable />
</EChartsBarChart>

The difference is under the hood: these compound children are declarative configuration slots rather than visual DOM nodes. The root reads their props and compiles an ECharts option, which ECharts paints with Canvas by default or SVG when renderer="svg".

The config is the same contract as every EvilCharts chart — each key maps a data key to a label and a per-theme colors array. See Chart Config for the full shape. Colors resolve from CSS variables at runtime, so dark mode just works.

SVG Renderer

Pass renderer="svg" to the chart root to opt into ECharts’ SVG renderer. Omit it to use the default Canvas renderer.

Interactive Selection

Add isClickable to any <Bar> (and to <Legend>) to make those series selectable. Use the onSelectionChange callback on <EChartsBarChart> to handle selection events:

<EChartsBarChart
	{data}
	config={chartConfig}
	onSelectionChange={(selectedDataKey) => {
		if (selectedDataKey) {
			console.log('Selected:', selectedDataKey);
		} else {
			console.log('Deselected');
		}
	}}
>
	<EChartsBarChart.XAxis dataKey="month" />
	<EChartsBarChart.Legend isClickable />
	<EChartsBarChart.Tooltip />
	<EChartsBarChart.Bar dataKey="desktop" variant="default" isClickable />
	<EChartsBarChart.Bar dataKey="mobile" variant="default" isClickable />
</EChartsBarChart>

Loading State

Buffer Bar

Examples

Examples of the bar chart with different variants. Each <Bar> sets its own variant; the chart-wide stackType and layout shape the rest.

Hover Highlight

Max Value Highlight

Gradient Colors

Bar Variants

Stack Types

Horizontal Layout

Glowing Bars

Ordered dither

Set renderStyle="dither" to use the independent ordered-dither treatment inspired by Dither Kit. Axes, tooltips, selection, and the ECharts renderer stay intact.

API Reference

The props below are grouped by the part they belong to. Regardless of renderer, each part is declarative config the root compiles, but the API mirrors the LayerChart sibling one-to-one.

EChartsBarChart

The root container. It owns the data, shared selection state, loading skeleton, and optional native dataZoom brush. Everything visual composes as children and compiles into the ECharts option.

PropTypeDefaultDescription
data*TData[]

The chart data — an array of objects, one per data point (TData extends Record<string, unknown>).

config*ChartConfig

Defines the chart’s series. Each key matches a data key, with a label and a per-theme colors array. Same contract as every EvilCharts chart — see Chart Config .

children*Snippet

The composed chart parts — <Grid />, <XAxis />, <YAxis />, <Legend />, <Tooltip />, and one or more <Bar />.

classstring

Additional CSS classes for the chart container.

renderer canvas| svg"canvas"

Rendering engine used by ECharts. Use "svg" for an SVG-backed chart surface; omit the prop to keep the Canvas default.

renderStyle native| dither"native"

Selects native ECharts paint or EvilCharts’ ordered-dither rendering.

ditherVariant gradient| dotted| hatched| solid"gradient"

Default ordered-dither pattern used by the chart’s series.

ditherCellSizenumber2

Dither cell size in CSS pixels.

bloom off| low| high| aura"off"

Optional glow applied to dithered marks. It has no effect in native rendering mode.

stackType default| stacked| percent"default"

How multiple bars combine. "default" renders them side by side, "stacked" stacks them, and "percent" normalizes them to a percentage distribution.

layout vertical| horizontal"vertical"

Bar orientation. With "horizontal", bars lay sideways and the axes swap — the <YAxis /> shows categories and the <XAxis /> shows values.

barRadiusnumber2

Default corner radius for every <Bar />, in pixels. Each <Bar /> can override it with its own radius prop.

animationbooleantrue

Master switch for the intro grow-in. Pass false to render the bars instantly, regardless of animationType.

animationType none| left-to-right| right-to-left| center-out| edges-in"left-to-right"

Order in which bars grow into view, inherited by every <Bar />. Bars rise from their baseline with a per-datum stagger. "none" disables it — devices set to OS reduce-motion fall back to "none" automatically.

barGapnumber

Gap between bars in the same category (with multiple series), in pixels.

barCategoryGapnumber

Gap between bar categories, in pixels.

defaultSelectedDataKeystring | nullnull

The series selected on first render.

onSelectionChange(key: string | null) => void

Fires when a series is selected or deselected via a clickable <Bar /> or <Legend />. Receives the selected data key, or null when deselected.

enableMaxValueHighlightbooleanfalse

Colors only the tallest column and mutes every other. With several series the comparison is per column (totals across all series), so a whole stack or group highlights together.

referenceLinenumber | nullnull

Draws a dashed reference line across the value axis. Useful for medians, targets, and thresholds.

referenceLineFormatter(value: number) => string

Formats the label attached to referenceLine.

onDataHover(datum: BarHoverDatum | null) => void

Reports the category row under the pointer, and null when the pointer leaves the plot. This powers block-level readouts without coupling the chart to their layout.

isLoadingbooleanfalse

Shows the animated shimmer skeleton while data loads.

loadingBarsnumber12

Number of bars in the loading skeleton.

xDataKeykeyof TData & string

The data key used for the category axis. Falls back to the axis dataKey; also read by the brush footer.

chartOptionsRecord<string, unknown>

Escape hatch merged over the underlying ECharts option object. See the ECharts option documentation .

accessibilityChartAccessibility

Names and optionally describes the chart wrapper. It remains a group, so interactive legends and marks stay available to assistive technology.

Bar

A single bar series. Each <Bar /> carries its own fill variant, radius, glow, buffer, and clickability, so a chart can hold any number of bars with mixed styles.

PropTypeDefaultDescription
dataKey*string

The series key. Must exist on both the data rows and the chart config.

variant default| hatched| duotone| duotone-reverse| gradient| stripped| blocks| expandable| isometric"default"

The bar’s fill style, applied to this bar only. The default variant renders the full vertical color gradient for multi-color configs; blocks renders the bar as a stack of segments over a muted grid of the same segments; isometric draws dimensional front, top, and side faces.

radiusnumber

The corner radius of this bar, in pixels. Falls back to the chart’s barRadius when omitted.

animationType none| left-to-right| right-to-left| center-out| edges-in

The grow-in order for this bar series. Falls back to the chart’s animationType when omitted.

isClickablebooleanfalse

Lets this bar be selected by clicking it. When any bar is selected, unselected bars become semi-transparent.

enableHoverHighlightbooleanfalse

Hovering over a bar dims every other bar, keeping focus on one series.

glowingbooleanfalse

Applies a soft outer glow to this bar series.

bufferBarbooleanfalse

Renders this series’ last data point with a hatched (diagonal lines) pattern and a series-colored outline while the rest stay solid. Useful for flagging projected or incomplete data at the end of a series.

ditherVariant gradient| dotted| hatched| solid

Overrides the root ordered-dither pattern for this bar series only.

XAxis and YAxis

The two axes. In the default (vertical) layout <XAxis /> is the category axis and <YAxis /> the value axis; layout="horizontal" swaps the roles. Include an axis to show its tick labels, omit it to hide them. Both hide automatically while loading, and the value axis formats ticks as percentages when stackType="percent".

PropTypeDefaultDescription
dataKeystring

The category key for the axis. Overrides the root xDataKey.

tickFormatter(value: string, index: number) => string

Formats the axis tick labels. Category values arrive as strings.

labelstring

An axis title centered outside the tick labels — below the <XAxis />, alongside the <YAxis />. Hidden while loading.

hideDotsbooleanfalse

Hides the small tick dots that sit beside this axis’s labels.

Grid

The background grid lines. Include it to draw the dashed split lines on the value axis; omit it and they don’t render. Takes no props.

Tooltip

The hover tooltip. Include it to enable the tooltip; omit it and none shows. It reads selection state, so its content dims unselected series.

PropTypeDefaultDescription
variant default| frosted-glass"default"

The visual style of the tooltip surface.

roundness sm| md| lg| xl"lg"

Controls the border-radius of the tooltip.

defaultIndexnumber

Shows the tooltip by default at the given data point index, with no hover.

position fixed| variable"variable"

How the tooltip is anchored. "variable" lets it follow the pointer, and "fixed" pins it near the top of the chart while only tracking the pointer’s X.

Legend

The series legend, rendered as HTML above the chart surface. Include it to show the legend; omit it and none shows. With isClickable, each entry toggles selection of its series.

PropTypeDefaultDescription
variant square| circle| circle-outline| rounded-square| rounded-square-outline| vertical-bar| horizontal-bar

The visual style of the legend indicators.

align left| center| right"right"

Horizontal placement of the legend.

verticalAlign top| middle| bottom"top"

Vertical placement of the legend.

isClickablebooleanfalse

Lets each legend entry toggle selection of its series.

Brush

An optional zoom brush below the chart — a themed mini chart driven by ECharts’ native dataZoom. Include <EChartsBarChart.Brush /> to render it; dragging the range filters the main chart.

PropTypeDefaultDescription
heightnumber56

Height of the brush preview strip in pixels.

formatLabel(value: string | number, index: number) => string

Formats the range-handle labels below the brush.

onChange(range: { startIndex: number; endIndex: number }) => void

Fires when the brush selection range changes.