Composed Chart

Documentation Index

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

Beautifully designed composed charts combining bars and lines, powered by Apache ECharts

Basic Chart

Installation

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

Usage

The ECharts composed chart is composible, sharing the Recharts twin's API shape. <EChartsComposedChart> is the container, and every part hangs off it as a compound member — <EChartsComposedChart.Grid>, <EChartsComposedChart.XAxis>, <EChartsComposedChart.YAxis>, <EChartsComposedChart.Legend>, <EChartsComposedChart.Tooltip>, and one or more <EChartsComposedChart.Bar> and <EChartsComposedChart.Line> — so a single import gives you the whole chart. Each <Bar> carries its own variant, glow, and isClickable, and each <Line> its own strokeVariant, curveType, glow, and isClickable, so one chart can freely mix bar and line styles.

import { EChartsComposedChart, type ChartConfig } from "@/components/evilcharts/charts/echarts-composed-chart";
const chartConfig = {
  revenue: {
    label: "Revenue",
    colors: { light: ["#3b82f6"], dark: ["#6A5ACD"] },
  },
  profit: {
    label: "Profit",
    colors: { light: ["#10b981"], dark: ["#34d399"] },
  },
} satisfies ChartConfig;
 
<EChartsComposedChart xDataKey="month" data={data} config={chartConfig}>
  <EChartsComposedChart.Grid />
  <EChartsComposedChart.XAxis dataKey="month" />
  <EChartsComposedChart.YAxis />
  <EChartsComposedChart.Legend isClickable />
  <EChartsComposedChart.Tooltip />
  <EChartsComposedChart.Bar dataKey="revenue" variant="gradient" isClickable />
  <EChartsComposedChart.Line dataKey="profit" strokeVariant="dashed" isClickable>
    <EChartsComposedChart.Dot variant="default" />
    <EChartsComposedChart.ActiveDot variant="colored-border" />
  </EChartsComposedChart.Line>
</EChartsComposedChart>

The only real difference from the Recharts twin 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), same behavior; the children are just 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 your CSS variables at runtime, so dark mode just works.

Interactive Selection

Add isClickable to any <Bar>, <Line>, or <Legend> to make its series selectable, and handle events with the onSelectionChange callback on <EChartsComposedChart>:

<EChartsComposedChart
  data={data}
  config={chartConfig}
  onSelectionChange={(selectedDataKey) => {
    if (selectedDataKey) {
      console.log("Selected:", selectedDataKey);
    } else {
      console.log("Deselected");
    }
  }}
>
  <EChartsComposedChart.XAxis dataKey="month" />
  <EChartsComposedChart.Legend isClickable />
  <EChartsComposedChart.Tooltip />
  <EChartsComposedChart.Bar dataKey="revenue" isClickable />
  <EChartsComposedChart.Line dataKey="profit" isClickable />
</EChartsComposedChart>

Loading State

isLoading='true'

Examples

Examples of the composed chart with different variants. Customize each <Bar> with a variant, and each <Line> with a strokeVariant, curveType, and more.

Gradient Colors

gradient colors

Bar Variants

<Bar variant='hatched' />
<Bar variant='duotone' />
<Bar variant='gradient' />
<Bar variant='stripped' />

Line Stroke Variants

<Line strokeVariant='dashed' />
<Line strokeVariant='animated-dashed' />

Curve Types

<Line curveType='bump' />

Line Dots

<Dot /> and <ActiveDot />

Hover Highlight

<Bar enableHoverHighlight />

Glowing Effects

<Bar glow /> and <Line glow />

API Reference

The chart is composed of several parts; the props below are grouped by part. On canvas each part is config the root compiles, but the API mirrors the Recharts twin one-to-one.

EChartsComposedChart

The root container. It owns the data, shared selection state, loading skeleton, and optional native dataZoom brush. Everything visual is composed as its children and compiled 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 every bar and line 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 /> and <Line />.

classNamestring

Additional CSS classes for the chart container.

xDataKeykeyof TData & string

The data key for the x-axis categories. Falls back to the <XAxis dataKey="…" /> value, then to the first data column no series claims.

curveTypelinear|smooth|bump|monotone|monotoneX|monotoneY|natural|step"linear"

Default curve interpolation inherited by every <Line />; each may override it locally.

animationbooleantrue

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

animationTypenone|left-to-right|right-to-left|center-out|edges-in"left-to-right"

The intro animation inherited by every <Bar /> and <Line />. Any value but "none" plays the draw-in: lines trace in left-to-right while bars grow from their baseline, staggered per-column in the chosen direction (left-to-right, right-to-left, center-out, edges-in). "none" disables it; the OS reduce-motion preference falls back to "none" automatically.

barGapnumber | string

The gap between bars in the same category (ECharts accepts a percentage like "30%" or a pixel number).

barCategoryGapnumber | string

The gap between bar categories.

defaultSelectedDataKeystring | nullnull

The series selected on first render.

onSelectionChange(key: string | null) => void

Fires when a series is selected or deselected — by clicking a clickable <Bar />, <Line />, or <Legend /> entry. Receives the selected data key, or null when deselected.

isLoadingbooleanfalse

Shows the animated loading skeleton.

loadingBarsnumber12

Number of bars in the loading skeleton.

chartOptionsRecord<string, unknown>

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

Bar

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

PropTypeDefaultDescription
dataKey*string

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

variantdefault|hatched|duotone|duotone-reverse|gradient|stripped"default"

The bar fill style, for this bar only.

radiusnumber4

The corner radius of the bar in pixels.

animationTypenone|left-to-right|right-to-left|center-out|edges-in

The grow-in order for this bar (the first declared series' value drives the chart). Falls back to the chart's animationType when omitted.

glowbooleanfalse

Applies a soft neon glow (a colored canvas shadow) to this bar.

isClickablebooleanfalse

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

enableHoverHighlightbooleanfalse

Hovering a column dims this bar's other columns, easing focus on a single data point.

barPropsPartial<BarSeriesOption>

Escape hatch merged into the raw ECharts bar series.

Line

A single line series. Each <Line /> carries its own stroke, curve, glow, and clickability, so a chart can hold any number of lines.

PropTypeDefaultDescription
dataKey*string

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

strokeVariantsolid|dashed|animated-dashed"solid"

The stroke style for this line.

curveTypelinear|smooth|bump|monotone|monotoneX|monotoneY|natural|step

The curve interpolation for this line. Falls back to the chart's curveType when omitted.

animationTypenone|left-to-right|right-to-left|center-out|edges-in

The intro reveal for this line (the first declared series' value drives the chart). Falls back to the chart's animationType when omitted.

connectNullsbooleanfalse

Whether to connect line segments across null or missing values.

glowbooleanfalse

A soft neon glow for this line — a colored blur that follows its color along its length.

isClickablebooleanfalse

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

childrenReactNode

Optional <Dot /> and <ActiveDot /> that add point markers to this line.

linePropsPartial<LineSeriesOption>

Escape hatch merged into the raw ECharts line series.

Dot and ActiveDot

Point markers composed inside a <Line />. <Dot /> is the resting marker; <ActiveDot /> is the hovered marker. They render nothing on their own — the parent <Line /> reads their variant.

PropTypeDefaultDescription
variantdefault|border|colored-border"default"

The visual style of the point marker.

XAxis and YAxis

The category and value axes. Include <XAxis /> for the x-axis labels and <YAxis /> for the y-axis; omit either to hide it. Both hide automatically while loading.

PropTypeDefaultDescription
dataKeystring

The data key for the axis values.

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

Formats the axis tick labels.

labelstring

An axis title. Rendered centered below the x-axis tick labels, or rotated beside the y-axis ones.

hideDotsbooleanfalse

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

Grid

The background grid lines. Include it to render the dashed horizontal split lines; omit it and they don't draw. Takes no props.

Tooltip

The hover tooltip. Include it to enable the tooltip; omit it and none shows. It reads the selection state and 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 this data point index.

cursorbooleantrue

Whether the vertical cursor line follows the pointer on hover.

positionfixed|variable"variable"

How the tooltip is anchored. variable follows both axes (default); fixed pins the tooltip near the top and only tracks 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 <EChartsComposedChart.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.