Line 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 line charts powered by Apache ECharts

Basic Chart

Installation

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

Usage

The ECharts line chart is composable, sharing the Recharts twin's API shape. <EChartsLineChart> is the container, and every part hangs off it as a compound member — <EChartsLineChart.Grid>, <EChartsLineChart.XAxis>, <EChartsLineChart.YAxis>, <EChartsLineChart.Legend>, <EChartsLineChart.Tooltip>, and one or more <EChartsLineChart.Line> — so a single import gives you the whole chart. Each <Line> carries its own strokeVariant, curveType, glowing, enableBufferLine, and isClickable, so one chart can mix stroke styles and make only some series interactive.

import { EChartsLineChart, type ChartConfig } from "@/components/evilcharts/charts/echarts-line-chart";
<EChartsLineChart data={data} config={chartConfig} curveType="monotone">
  <EChartsLineChart.Grid />
  <EChartsLineChart.XAxis dataKey="month" />
  <EChartsLineChart.YAxis />
  <EChartsLineChart.Legend isClickable />
  <EChartsLineChart.Tooltip />
  <EChartsLineChart.Line dataKey="desktop" strokeVariant="solid" isClickable>
    <EChartsLineChart.Dot variant="border" />
    <EChartsLineChart.ActiveDot variant="colored-border" />
  </EChartsLineChart.Line>
  <EChartsLineChart.Line dataKey="mobile" strokeVariant="dashed" glowing>
    <EChartsLineChart.ActiveDot variant="default" />
  </EChartsLineChart.Line>
</EChartsLineChart>

The one 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 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 your CSS variables at runtime, so dark mode just works.

Interactive Selection

Add isClickable to any <Line> (and to <Legend>) to make those series selectable, then handle events via the onSelectionChange callback on <EChartsLineChart>:

<EChartsLineChart
  data={data}
  config={chartConfig}
  onSelectionChange={(selectedDataKey) => {
    if (selectedDataKey) {
      console.log("Selected:", selectedDataKey);
    } else {
      console.log("Deselected");
    }
  }}
>
  <EChartsLineChart.XAxis dataKey="month" />
  <EChartsLineChart.Legend isClickable />
  <EChartsLineChart.Tooltip />
  <EChartsLineChart.Line dataKey="desktop" strokeVariant="solid" isClickable />
  <EChartsLineChart.Line dataKey="mobile" strokeVariant="solid" isClickable />
</EChartsLineChart>

Loading State

isLoading='true'

Buffer Line

enableBufferLine='true'

Hover Reveal

enableHoverReveal='true'

Examples

Examples with different settings. Change strokeVariant on a <Line> or curveType on the chart to restyle it.

Gradient Colors

gradient colors
gradient colors - bump

Curve Types

curveType='bump'
curveType='step'
curveType='monotoneY'

Stroke Variants

strokeVariant='solid'
strokeVariant='dashed'
strokeVariant='animated-dashed'

Glowing Lines

glowing - gradient colors
glowing - solid colors

API Reference

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

EChartsLineChart

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 the chart's series — each key matches a data key with a label and 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 <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 <Line /> claims.

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

Default curve interpolation inherited by every <Line />. Each <Line /> 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 <Line />. Any value but "none" plays ECharts' native progressive draw-in (the line traces in and dots pop up as its front passes; direction values exist for API parity with the Recharts twin). "none" disables it; devices set to OS reduce-motion fall back to "none" automatically.

enableHoverHighlightbooleanfalse

Highlights the hovered line by dimming the rest — the hover twin of click selection. Dim levels match the selection styling; a glowing line's glow and a buffer line's dashed tail dim and brighten with their parent.

enableHoverRevealbooleanfalse

On hover, colors each line up to the pointer's x-position and mutes the rest to a neutral gray, with the active dot at the cursor. A standalone hover mode that takes visual precedence over enableHoverHighlight; idle, the chart renders normally.

defaultSelectedDataKeystring | nullnull

The series selected on first render.

onSelectionChange(key: string | null) => void

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

isLoadingbooleanfalse

Shows the animated loading skeleton.

loadingPointsnumber14

Number of points in the loading skeleton.

chartOptionsRecord<string, unknown>

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

Line

A single line series. Each <Line /> is self-contained — its own stroke, glow, and clickability — so a chart can hold any number of independently styled 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.

strokeWidthnumber0.8

Stroke thickness for this line, in pixels.

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 draw-in for this line (the first <Line />'s value drives the chart). Falls back to the chart's animationType when omitted.

connectNullsbooleanfalse

Whether to connect line segments across null or missing values.

isClickablebooleanfalse

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

glowingbooleanfalse

Applies a soft outer glow to this line, tinted with its series color.

enableBufferLinebooleanfalse

Renders this line's last segment as a dashed buffer while the rest stays solid — useful for projected or incomplete data at the end of a series.

childrenReactNode

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

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 x-axis labels and <YAxis /> for the y-axis; omit either to hide it. Both hide automatically while the chart loads.

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 clear of the tick labels — centered below the x-axis labels, or rotated alongside 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 chart's selection state, dimming unselected series in its content.

PropTypeDefaultDescription
variantdefault|frosted-glass"default"

The visual style of the tooltip surface.

roundnesssm|md|lg|xl"lg"

Controls the border-radius of the tooltip.

cursorbooleantrue

Whether the vertical cursor line follows the pointer on hover.

positionfixed|variable"variable"

How the tooltip is anchored. "variable" follows both axes (the default). "fixed" pins the tooltip near the top of the chart 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 <EChartsLineChart.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.