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

Installation

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

Usage

The ECharts line chart is composable, sharing the LayerChart sibling’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.

<script lang="ts">
	import {
		EChartsLineChart,
		type ChartConfig
	} from '$lib/components/evilcharts/charts/echarts-line-chart/index.js';
</script>
<EChartsLineChart {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 difference from the LayerChart sibling 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 your 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 <Line> (and to <Legend>) to make those series selectable, then handle events via the onSelectionChange callback on <EChartsLineChart>:

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

Buffer Line

Hover Reveal

Examples

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

Gradient Colors

Curve Types

Stroke Variants

Glowing Lines

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 chart is composed of several parts; the props below are grouped by part. Regardless of renderer, each part is declarative config the root compiles, but the API mirrors the LayerChart sibling 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*Snippet

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

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.

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.

curveType linear| 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.

animationType none| 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 LayerChart sibling). "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 .

accessibilityChartAccessibility

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

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.

strokeVariant solid| dashed| animated-dashed"solid"

The stroke style for this line.

strokeWidthnumber0.8

Stroke thickness for this line, in pixels.

curveType linear| smooth| bump| monotone| monotoneX| monotoneY| natural| step

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

animationType none| 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.

ditherVariant gradient| dotted| hatched| solid

Overrides the root ordered-dither pattern for this line only.

childrenSnippet

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
variant default| 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
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.

cursorbooleantrue

Whether the vertical cursor line follows the pointer on hover.

position fixed| 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 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 <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.