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

Basic Chart

Installation

npx shadcn@latest add @evilcharts/echarts-bar-chart

Usage

The ECharts bar chart is composible, sharing the Recharts twin'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.

import { EChartsBarChart, type ChartConfig } from "@/components/evilcharts/charts/echarts-bar-chart";
<EChartsBarChart data={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 one real difference is under the hood: ECharts renders to a <canvas>, so these children never mount as DOM. The root reads their props and compiles them into the ECharts option object — same JSX, same presence semantics (omit a part and it doesn't render), but the children are declarative config, not live DOM nodes.

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.

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={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

isLoading='true'

Buffer Bar

<Bar bufferBar />

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

<Bar enableHoverHighlight />

Max Value Highlight

<EChartsBarChart enableMaxValueHighlight />

Gradient Colors

gradient colors

Bar Variants

variant='default'
variant='hatched'
variant='duotone'
variant='duotone-reverse'
variant='gradient'
variant='stripped'
variant='blocks'
variant='expandable'

Stack Types

stackType='stacked'
stackType='percent'

Horizontal Layout

layout='horizontal'

Glowing Bars

<Bar glowing /> - desktop
<Bar glowing /> - mobile

API Reference

The props below are grouped by the part they belong to. On canvas each part is declarative config the root compiles, but the API mirrors the Recharts twin 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*ReactNode

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

classNamestring

Additional CSS classes for the chart container.

stackTypedefault|stacked|percent"default"

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

layoutvertical|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.

animationTypenone|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.

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.

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.

variantdefault|hatched|duotone|duotone-reverse|gradient|stripped|blocks|expandable"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.

radiusnumber

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

animationTypenone|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.

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
variantdefault|frosted-glass"default"

The visual style of the tooltip surface.

roundnesssm|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.

positionfixed|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 canvas. Include it to show the legend; omit it and none shows. With isClickable, each entry toggles selection of its series.

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

The visual style of the legend indicators.

alignleft|center|right"right"

Horizontal placement of the legend.

verticalAligntop|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.