elements
Demos UI Feed Discuss Install
Style System
  • Style
  • Themes
  • Behaviors
Forms
  • Button
  • ButtonGroup
  • Checkbox
  • ColorPicker
  • Combobox
  • Field
  • FileUpload
  • Input
  • InputGroup
  • InputOTP
  • Label
  • NativeSelect
  • NumberInput
  • PasswordInput
  • RadioGroup
  • Select
  • Slider
  • Switch
  • TagsInput
  • Textarea
  • Toggle
  • ToggleGroup
Overlays
  • AlertDialog
  • Command
  • ContextMenu
  • Dialog
  • Drawer
  • DropdownMenu
  • HoverCard
  • Menubar
  • NavigationMenu
  • Popover
  • Sheet
  • Toast
  • Tooltip
Display
  • Accordion
  • Alert
  • AspectRatio
  • Avatar
  • Badge
  • Breadcrumb
  • Card
  • Collapsible
  • Empty
  • Item
  • Kbd
  • Pagination
  • Progress
  • Separator
  • Skeleton
  • Spinner
  • Table
  • Tabs
  • Tree
Layout
  • Carousel
  • Resizable
  • ScrollArea
  • Sidebar
Dates
  • Calendar
  • DatePicker
  • DateRangePicker
  • TimePicker
Data
  • AreaChart
  • BarChart
  • Chart
  • DataTable
  • Kanban
  • LineChart
  • PieChart
  • RadarChart
  • RadialChart
  • VirtualList
Chat
  • Attachment
  • Message
  • MessageList
  • PromptInput
Elements UI / Data / LineChart

LineChart

Lines over categories with dots, curves, labels and a crosshair tooltip.

Default

A natural curve, no dots, a tooltip with no heading and no cursor.

Line Chart

January - June 2024

JanFebMarAprMayJun
Line chart
MonthDesktop
January186
February305
March237
April73
May209
June214
Trending up by 5.2% this month
Showing total visitors for the last 6 months
Code
<LineChart data={rows} config={{ desktop: { label: "Desktop", color: "var(--chart-1)" } }}
           x="month" curve="natural" margin={{ left: 12, right: 12 }}
           categoryAxis={{ tickFormatter: (v) => String(v).slice(0, 3) }}
           tooltip={{ hideLabel: true, cursor: false }} />

Usage

import { LineChart } from "@elements/ui/chart-line";
import type { ChartConfig } from "@elements/ui/chart";

const config: ChartConfig = {
  desktop: { label: "Desktop", color: "var(--chart-1)" },
  mobile: { label: "Mobile", color: "var(--chart-2)" },
};

<LineChart data={rows} {config} x="month" curve="natural" />
<LineChart data={rows} {config} x="month" dots legend labels />

Examples

Linear

curve=linear joins the points with straight segments.

Line Chart - Linear

January - June 2024

JanFebMarAprMayJun
Line chart
MonthDesktop
January186
February305
March237
April73
May209
June214
Code
<LineChart data={rows} {config} x="month" series={["desktop"]} curve="linear" ... />

Step

curve=step holds each value to the midpoint; stepBefore and stepAfter hold it before or after.

Line Chart - Step

January - June 2024

JanFebMarAprMayJun
Line chart
MonthDesktop
January186
February305
March237
April73
May209
June214
Code
<LineChart data={rows} {config} x="month" series={["desktop"]} curve="step" ... />

Multiple

Every series in the config, one line each.

Line Chart - Multiple

January - June 2024

JanFebMarAprMayJun
Line chart
MonthDesktopMobile
January18680
February305200
March237120
April73190
May209130
June214140
Code
<LineChart data={rows} {config} x="month" curve="monotone"
           margin={{ left: 12, right: 12 }} tooltip={{ cursor: false }} />

Dots

A dot on every point and a larger active dot on hover, each ringed in the surface color.

Line Chart - Dots

January - June 2024

JanFebMarAprMayJun
Line chart
MonthDesktop
January186
February305
March237
April73
May209
June214
Code
<LineChart data={rows} {config} x="month" series={["desktop"]} curve="natural"
           dots activeDot={{ r: 6 }} tooltip={{ hideLabel: true, cursor: false }} />

Custom dots

dots shape=commit draws a ring on a stem, a custom dot.

Line Chart - Custom Dots

January - June 2024

JanFebMarAprMayJun
Line chart
MonthDesktop
January186
February305
March237
April73
May209
June214
Code
<LineChart data={rows} {config} x="month" series={["desktop"]} curve="natural"
           dots={{ shape: "commit", r: 4 }} activeDot={{ shape: "commit", r: 5 }} ... />

Dots colors

colorByRow fills each dot from its row's fill.

Line Chart - Dots Colors

January - June 2024

Line chart
BrowserVisitors
Chrome275
Safari200
Firefox187
Edge173
Other90
Code
<!-- each row's fill colors its dot -->
<LineChart data={browsers} config={browserConfig} x="browser" series={["visitors"]}
           curve="natural" categoryAxis={false} margin={{ top: 24, left: 24, right: 24 }}
           dots={{ r: 5, colorByRow: true }} activeDot={{ r: 6, colorByRow: true }}
           tooltip={{ indicator: "line", nameKey: "visitors", hideLabel: true, cursor: false }} />

Label

A value above every point.

Line Chart - Label

January - June 2024

JanFebMarAprMayJun18630523773209214
Line chart
MonthDesktop
January186
February305
March237
April73
May209
June214
Code
<LineChart data={rows} {config} x="month" series={["desktop"]} curve="natural"
           margin={{ top: 20, left: 12, right: 12 }} dots activeDot={{ r: 6 }}
           labels={{ position: "top", offset: 12 }} tooltip={{ indicator: "line", cursor: false }} />

Custom label

Labels from another field, formatted through the config.

Line Chart - Custom Label

January - June 2024

ChromeSafariFirefoxEdgeOther
Line chart
BrowserVisitors
Chrome275
Safari200
Firefox187
Edge173
Other90
Code
<LineChart data={browsers} config={browserConfig} x="browser" series={["visitors"]} curve="natural"
           categoryAxis={false} margin={{ top: 24, left: 24, right: 24 }}
           dots activeDot={{ r: 6 }}
           labels={{ key: "browser", offset: 12, formatter: (v) => browserConfig[String(v)].label }}
           tooltip={{ indicator: "line", nameKey: "visitors", hideLabel: true, cursor: false }} />

Interactive

The header switches the series; 91 points with skipping ticks and a crosshair cursor.

Line Chart - Interactive

Showing total visitors for the last 3 months

Apr 3Apr 14Apr 25May 6May 17May 28Jun 8Jun 30
Line chart
DateDesktop
2024-04-01286
2024-04-02136
2024-04-03267
2024-04-04121
2024-04-05326
2024-04-06204
2024-04-07353
2024-04-08289
2024-04-09359
2024-04-10314
2024-04-11160
2024-04-12466
2024-04-13138
2024-04-14472
2024-04-15258
2024-04-16359
2024-04-17158
2024-04-18268
2024-04-19309
2024-04-20151
2024-04-21231
2024-04-22122
2024-04-23185
2024-04-24278
2024-04-25331
2024-04-26394
2024-04-27144
2024-04-28270
2024-04-29109
2024-04-30362
2024-05-01472
2024-05-02265
2024-05-03266
2024-05-04270
2024-05-05196
2024-05-06387
2024-05-07198
2024-05-08433
2024-05-09461
2024-05-10389
2024-05-11312
2024-05-12219
2024-05-13176
2024-05-14364
2024-05-15197
2024-05-1693
2024-05-17324
2024-05-18126
2024-05-19273
2024-05-20325
2024-05-21140
2024-05-22449
2024-05-23100
2024-05-24373
2024-05-25354
2024-05-26182
2024-05-27157
2024-05-28123
2024-05-29305
2024-05-30427
2024-05-31288
2024-06-01202
2024-06-02116
2024-06-03182
2024-06-04406
2024-06-05156
2024-06-06340
2024-06-07251
2024-06-08281
2024-06-0993
2024-06-10271
2024-06-11225
2024-06-12377
2024-06-13197
2024-06-14121
2024-06-15123
2024-06-16165
2024-06-17102
2024-06-18266
2024-06-19306
2024-06-20301
2024-06-21138
2024-06-22355
2024-06-23453
2024-06-24273
2024-06-25444
2024-06-26289
2024-06-27405
2024-06-28308
2024-06-29344
2024-06-30266
Code
<LineChart data={daily} config={dailyConfig} x="date" series={[state.series]}
           class="chart-demo-wide" curve="monotone" margin={{ left: 12, right: 12 }}
           categoryAxis={{ tickFormatter: shortDate, minTickGap: 32 }}
           tooltip={{ nameKey: "views", labelFormatter: (_, row) => longDate(row.date) }} />

Legend, value axis and toggles

A legend whose items hide and show their line; a value axis with four ticks.

JanFebMarAprMayJun0150300450
Line chart
MonthDesktopMobile
January18680
February305200
March237120
April73190
May209130
June214140
hidden: none
Code
<LineChart data={rows} {config} x="month" curve="monotone" dots
           legend={{ toggle: true }} hidden={state.hidden}
           valueAxis={{ tickCount: 4 }} />

Missing values

A null breaks the line; connectNulls draws across it. The tooltip leaves out a series with no value, and a month with none shows no tooltip.

JanFebMarAprMayJun
Line chart
MonthDesktopMobile
January18680
February305200
March120
April73190
May209
June214140
JanFebMarAprMayJun
Line chart
MonthDesktopMobile
January18680
February305200
March120
April
May209
June214140
Code
<!-- null values break a line unless connectNulls -->
<LineChart data={rowsWithNulls} {config} x="month" dots />
<LineChart data={rowsWithNulls} {config} x="month" dots connectNulls />

Controlled and keyboard

Tab to the chart; arrows move the crosshair, Home and End jump, Escape hides the tooltip.

JanFebMarAprMayJun
Line chart
MonthDesktopMobile
January18680
February305200
March237120
April73190
May209130
June214140
active: -1 changes: 0 clicked: -1
Code
<LineChart data={rows} {config} x="month" active={state.active}
           onActiveChange={() => state.changes++} strokeWidth={3}
           onItemClick={(i) => state.clicked = i} />

Synced charts

Two charts with one syncId share the active month and its tooltip.

JanFebMarAprMayJun
Line chart
MonthDesktop
January186
February305
March237
April73
May209
June214
JanFebMarAprMayJun
Line chart
MonthMobile
January80
February200
March120
April190
May130
June140
Code
<!-- the same syncId: hovering or keying one chart shows the same month in the other -->
<LineChart data={rows} {config} x="month" series={["desktop"]} syncId="traffic" />
<LineChart data={rows} {config} x="month" series={["mobile"]} syncId="traffic" />

Two value axes

Desktop on the left axis, mobile on its own axis on the right, each scaled to its data.

JanFebMarAprMayJun080160240305050100150200
  • Desktop
  • Mobile
Line chart
MonthDesktopMobile
January18680
February305200
March237120
April73190
May209130
June214140
Code
<!-- mobile on a second value axis, ticked on the right -->
<LineChart data={rows} {config} x="month"
           valueAxis={[
             { domain: [0, "dataMax"] },
             { orientation: "right", series: ["mobile"], domain: [0, "dataMax"] },
           ]} />

Vertical layout

Months run down the chart and values across it; the arrow keys follow them up and down.

080160240320JanFebMarAprMayJun
Line chart
MonthDesktopMobile
January18680
February305200
March237120
April73190
May209130
June214140
Code
<!-- categories down the chart, values across -->
<LineChart data={rows} {config} x="month" layout="vertical" valueAxis dots />

Legend type per series

legendType on a config entry sets that series' legend icon; none leaves a drawn series out of the legend.

JanFebMarAprMayJun
  • Desktop
Line chart
MonthDesktopMobile
January18680
February305200
March237120
April73190
May209130
June214140
Code
<!-- desktop's legend icon is a line; mobile is drawn but not in the legend -->
<LineChart data={rows} x="month" legend config={{
  desktop: { label: "Desktop", color: "var(--chart-1)", legendType: "line" },
  mobile: { label: "Mobile", color: "var(--chart-2)", legendType: "none" },
}} />

Animation timing

animation sets when the marks start moving, how long they take and their easing: a CSS easing name, a cubic-bezier, spring, or a function of progress.

JanFebMarAprMayJun
Line chart
MonthDesktopMobile
January18680
February305200
March237120
April73190
May209130
June214140
Code
<!-- wait 150ms, then take 900ms to enter or move to new data -->
<LineChart data={rows} {config} x="month"
           animation={{ begin: 150, duration: 900, easing: "linear" }} />

Legend and tooltip types

legendType on a config entry sets that series' legend icon, and none leaves a drawn series out of the legend; tooltipType none leaves it out of the tooltip.

JanFebMarAprMayJun
  • Desktop
  • Mobile
Line chart
MonthDesktopMobileOther
January1868045
February305200100
March237120150
April7319050
May209130100
June214140160
Code
<!-- desktop's legend icon is a line; mobile is left out of the tooltip, other out of the legend -->
<LineChart data={rows} x="month" legend config={{
  desktop: { label: "Desktop", color: "var(--chart-1)", legendType: "line" },
  mobile: { label: "Mobile", color: "var(--chart-2)", tooltipType: "none" },
  other: { label: "Other", color: "var(--chart-3)", legendType: "none" },
}} />

Dashed line

strokeDasharray on a config entry dashes that series' line; the others stay solid.

JanFebMarAprMayJun
Line chart
MonthDesktopMobile
January18680
February305200
March237120
April73190
May209130
June214140
Code
<!-- strokeDasharray on a config entry dashes that line -->
<LineChart data={rows} x="month" config={{
  desktop: { label: "Desktop", color: "var(--chart-1)" },
  mobile: { label: "Mobile", color: "var(--chart-2)", strokeDasharray: "5 5" },
}} />

Data table

The data as a table; showTable shows it.

JanFebMarAprMayJun
Line chart
MonthDesktopMobile
January18680
February305200
March237120
April73190
May209130
June214140
Code
<LineChart data={rows} {config} x="month" showTable={state.table} />

Axis padding, log scale and a numeric axis

padding insets the first and last points; a log value axis spaces powers of ten evenly; a numeric category axis places each point by its value.

categoryAxis padding
JanFebMarAprMayJun
Line chart
MonthDesktop
January186
February305
March237
April73
May209
June214
valueAxis scale log
abcd1101001,000
Line chart
XValue
a1
b10
c100
d1,000
categoryAxis type number
02.557.510
Line chart
TValue
05
18
24
109
Code
<LineChart data={rows} {config} x="month" series={["desktop"]} dots
           categoryAxis={{ padding: { left: 24, right: 24 } }} />
<LineChart data={powers} config={valueConfig} x="x" series={["v"]} dots
           valueAxis={{ scale: "log", domain: ["auto", "auto"] }} />
<LineChart data={timed} config={valueConfig} x="t" series={["v"]} dots
           categoryAxis={{ type: "number" }} />

Moving to new data

animation matchBy pairs old and new items by a key, so each month slides to its new place; interpolate draws every frame with a function of your own, here one that starts each point after the one before.

JanFebMarAprMayJun
Line chart
MonthDesktop
January186
February305
March237
April73
May209
June214
JanFebMarAprMayJun
Line chart
MonthDesktop
January186
February305
March237
April73
May209
June214
Code
<!-- each month keeps its point: the window slides instead of every point changing value -->
<LineChart data={rows} {config} x="month" animation={{ matchBy: matchByDataKey("month") }} />
<!-- (items, t) => the items to draw: each matched item from prev to next, started one after another -->
<LineChart data={rows} {config} x="month" animation={{ interpolate: stagger }} />
Reference LineChart in the manual Every part, attribute, slot, key and data attribute.
Prev KanbanNext PieChart
Product
Manual Pricing Compare
Company
History Contact
Legal
Privacy Policy Acceptable Use Terms License Agreement
© Elements Dev Corporation 2026