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 / Chart

Chart

What every chart shares: the config and its colors, the tooltip, the legend, the palette and the data table.

Tooltip - Default

The category heading, then one row per series: swatch, name, value. Hover, tab in, tap, or drag a finger across the plot.

Tooltip - Default

tooltip={true}

MonTueWedThuFriSat
Bar chart
DateRunningSwimming
2024-07-15450300
2024-07-16380420
2024-07-17520120
2024-07-18140550
2024-07-19600350
2024-07-20480400
Code
<BarChart data={activities} config={activityConfig} x="date" stack="normal"
          categoryAxis={{ tickFormatter: weekday }}
          tooltip={{ /* the options below */ }} />

Usage

import type { ChartConfig } from "@elements/ui/chart";
import { BarChart } from "@elements/ui/chart-bar";

const config: ChartConfig = {
  desktop: { label: "Desktop", color: "var(--chart-1)", icon: "monitor" },
  mobile: { label: "Mobile", theme: { light: "var(--chart-2)", dark: "var(--chart-5)" } },
};

<BarChart data={rows} {config} x="month"
          tooltip={{ indicator: "line", labelFormatter: (label) => label.slice(0, 3) }}
          legend={{ position: "top", toggle: true }} />

Examples

Tooltip - Line Indicator

indicator=line draws a bar for each swatch.

Tooltip - Line Indicator

tooltip={{ indicator: "line" }}

MonTueWedThuFriSat
Bar chart
DateRunningSwimming
2024-07-15450300
2024-07-16380420
2024-07-17520120
2024-07-18140550
2024-07-19600350
2024-07-20480400
Code
tooltip={{ indicator: "line" }}

Tooltip - No Indicator

hideIndicator leaves names and values.

Tooltip - No Indicator

tooltip={{ hideIndicator: true }}

MonTueWedThuFriSat
Bar chart
DateRunningSwimming
2024-07-15450300
2024-07-16380420
2024-07-17520120
2024-07-18140550
2024-07-19600350
2024-07-20480400
Code
tooltip={{ hideIndicator: true }}

Tooltip - Color

color paints every swatch one color, over the config.

Tooltip - Color

tooltip={{ color: "var(--chart-5)" }}

MonTueWedThuFriSat
Bar chart
DateRunningSwimming
2024-07-15450300
2024-07-16380420
2024-07-17520120
2024-07-18140550
2024-07-19600350
2024-07-20480400
Code
tooltip={{ color: "var(--chart-5)" }}

Tooltip - Custom Label

labelKey heads the tooltip with a config label.

Tooltip - Custom Label

tooltip={{ labelKey: "activities", indicator: "line" }}

MonTueWedThuFriSat
Bar chart
DateRunningSwimming
2024-07-15450300
2024-07-16380420
2024-07-17520120
2024-07-18140550
2024-07-19600350
2024-07-20480400
Code
tooltip={{ labelKey: "activities", indicator: "line" }}

Tooltip - Label Formatter

labelFormatter writes the heading.

Tooltip - Label Formatter

tooltip={{ labelFormatter: (label) => fullDate(label) }}

MonTueWedThuFriSat
Bar chart
DateRunningSwimming
2024-07-15450300
2024-07-16380420
2024-07-17520120
2024-07-18140550
2024-07-19600350
2024-07-20480400
Code
tooltip={{ labelFormatter: (label) => fullDate(label) }}

Tooltip - No Label

hideLabel drops the heading.

Tooltip - No Label

tooltip={{ hideLabel: true }}

MonTueWedThuFriSat
Bar chart
DateRunningSwimming
2024-07-15450300
2024-07-16380420
2024-07-17520120
2024-07-18140550
2024-07-19600350
2024-07-20480400
Code
tooltip={{ hideLabel: true }}

Tooltip - Formatter

A unit after each value in the muted ink; formatter rewrites a value's text.

Tooltip - Formatter

tooltip={{ hideLabel: true, hideIndicator: true, unit: "kcal" }}

MonTueWedThuFriSat
Bar chart
DateRunningSwimming
2024-07-15450300
2024-07-16380420
2024-07-17520120
2024-07-18140550
2024-07-19600350
2024-07-20480400
Code
tooltip={{ hideLabel: true, hideIndicator: true, unit: "kcal" }}

Tooltip - Icons

Config icons replace swatches; defaultIndex shows the tooltip from the start.

Tooltip - Icons

defaultIndex: 1

MonTueWedThuFriSat
Bar chart
DateRunningSwimming
2024-07-15450300
2024-07-16380420
2024-07-17520120
2024-07-18140550
2024-07-19600350
2024-07-20480400
Code
const config = {
  running: { label: "Running", color: "var(--chart-1)", icon: "heart" },
  swimming: { label: "Swimming", color: "var(--chart-2)", icon: "waves" },
};

tooltip={{ hideLabel: true, cursor: false, defaultIndex: 1 }}

Tooltip - Advanced

A footer line under the items: here the day's total.

Tooltip - Advanced

footer: (row) => total

MonTueWedThuFriSat
Bar chart
DateRunningSwimming
2024-07-15450300
2024-07-16380420
2024-07-17520120
2024-07-18140550
2024-07-19600350
2024-07-20480400
Code
tooltip={{ hideLabel: true, unit: "kcal", footerLabel: "Total", footer: (row) => String(row.running + row.swimming) }}

Config and colors

Each config key becomes --color-<key> on the chart: a token, any CSS color (hex, hsl, oklch), or a theme pair for light and dark.

JanFebMarAprMayJun
  • Desktop
  • Mobile
Bar chart
MonthDesktopMobile
January18680
February305200
March237120
April73190
May209130
June214140
Code
const config: ChartConfig = {
  desktop: { label: "Desktop", theme: { light: "var(--chart-1)", dark: "var(--chart-7)" } },
  mobile: { label: "Mobile", color: "oklch(0.62 0.13 175)" }, // hex, hsl or oklch work too
};
// each key becomes --color-desktop, --color-mobile on the chart

Legend

Above or below the plot, with or without swatches.

  • Desktop
  • Mobile
JanFebMarAprMayJun
Line chart
MonthDesktopMobile
January18680
February305200
March237120
April73190
May209130
June214140
JanFebMarAprMayJun
  • Desktop
  • Mobile
Line chart
MonthDesktopMobile
January18680
February305200
March237120
April73190
May209130
June214140
Code
<LineChart data={rows} {config} x="month" legend={{ position: "top" }} />
<LineChart data={rows} {config} x="month" legend={{ hideIcon: true }} />

Palette

--chart-1 to --chart-8, in the order a config takes them. Switch the look and mode to see each theme's set.

  • --chart-1
  • --chart-2
  • --chart-3
  • --chart-4
  • --chart-5
  • --chart-6
  • --chart-7
  • --chart-8
Code
/* the theme's series colors; a config entry with no color takes the next slot */
color: var(--chart-1) ... var(--chart-8)

Long names

Long series names wrap inside the tooltip and the legend; nothing leaves the chart.

JanFebMarAprMayJun
  • Returning desktop visitors from Western Europe
  • First-time mobile visitors from North America
Bar chart
MonthReturning desktop visitors from Western EuropeFirst-time mobile visitors from North America
January18680
February305200
March237120
April73190
May209130
June214140
Code
const config = {
  desktop: { label: "Returning desktop visitors from Western Europe" },
  mobile: { label: "First-time mobile visitors from North America" },
};
<BarChart data={rows} {config} x="month" legend />

Tooltip - Options

itemSorter orders the rows; includeHidden keeps a hidden series; active keeps the tooltip shown; position fixes its spot; reverseDirection puts it left of the pointer.

JanFebMarAprMayJun
Bar chart
MonthDesktopMobileOther
January1868045
February305200100
March237120150
April7319050
May209130100
June214140160
JanFebMarAprMayJun
Line chart
MonthDesktopMobile
January18680
February305200
March237120
April73190
May209130
June214140
JanFebMarAprMayJun
Line chart
MonthDesktopMobile
January18680
February305200
March237120
April73190
May209130
June214140
JanFebMarAprMayJun
Bar chart
MonthDesktopMobile
January18680
February305200
March237120
April73190
May209130
June214140
JanFebMarAprMayJun
Bar chart
MonthDesktopMobile
January18680
February305200
March237120
April73190
May209130
June214140
Code
<BarChart ... tooltip={{ itemSorter: "value" }} />                        <!-- smallest value first -->
<LineChart ... hidden={["mobile"]} tooltip={{ includeHidden: true }} legend={{ toggle: true }} />
<LineChart ... tooltip={{ active: true, defaultIndex: 1 }} />             <!-- always shown -->
<BarChart ... tooltip={{ position: { x: 8, y: 8 } }} />                  <!-- a fixed corner -->
<BarChart ... tooltip={{ reverseDirection: { x: true } }} />             <!-- left of the pointer -->

Legend - Options

verticalAlign and align place the legend; iconType picks the swatch; formatter writes each name; itemSorter orders them.

  • Desktop
  • Mobile
  • Other
JanFebMarAprMayJun
Bar chart
MonthDesktopMobileOther
January1868045
February305200100
March237120150
April7319050
May209130100
June214140160
JanFebMarAprMayJun
  • OTHER
  • MOBILE
  • DESKTOP
Bar chart
MonthDesktopMobileOther
January1868045
February305200100
March237120150
April7319050
May209130100
June214140160
Code
<BarChart ... legend={{ verticalAlign: "top", align: "left", iconType: "circle" }} />
<!-- itemSorter: "name", "key", or a sort value per item: here the config order reversed -->
<BarChart ... legend={{ formatter: (name) => name.toUpperCase(), itemSorter: (item) => -keys.indexOf(item.key), iconType: "line" }} />

Legend - Size, offset and position

iconSize sets the swatch size; offset moves the legend away from the plot; position puts it beside the plot, over it at an inside spot, or at a point.

JanFebMarAprMayJun
  • Desktop
  • Mobile
Bar chart
MonthDesktopMobile
January18680
February305200
March237120
April73190
May209130
June214140
JanFebMarAprMayJun
  • Desktop
  • Mobile
Bar chart
MonthDesktopMobile
January18680
February305200
March237120
April73190
May209130
June214140
JanFebMarAprMayJun
  • Desktop
  • Mobile
Bar chart
MonthDesktopMobile
January18680
February305200
March237120
April73190
May209130
June214140
JanFebMarAprMayJun
  • Desktop
  • Mobile
Bar chart
MonthDesktopMobile
January18680
February305200
March237120
April73190
May209130
June214140
Code
<BarChart ... legend={{ iconSize: 14 }} />
<BarChart ... legend={{ offset: 16 }} />                                   <!-- 16px further from the plot -->
<BarChart ... legend={{ position: "insideTopRight", offset: 8, layout: "vertical" }} />
<BarChart ... legend={{ position: { x: 48, y: 8 } }} />                      <!-- a point in the chart box -->

Synced charts

Charts with one syncId share the active item and its tooltip, by position or, with syncMethod value, by name.

JanFebMarAprMayJun
Bar chart
MonthDesktopMobile
January18680
February305200
March237120
April73190
May209130
June214140
JanFebMarAprMayJun
Area chart
MonthDesktopMobile
January18680
February305200
March237120
April73190
May209130
June214140
JanuaryFebruaryMarchAprilMayJune
Radar chart
MonthDesktopMobile
January18680
February305200
March237120
April73190
May209130
June214140
Pie chart
BrowserVisitors
Chrome275
Safari200
Firefox187
Edge173
Other90
Radial chart
BrowserVisitors
Other90
Edge173
Firefox187
Safari200
Chrome275
Code
<!-- one syncId: a move in any chart shows the same month in the others -->
<BarChart data={rows} {config} x="month" syncId="months" />
<AreaChart data={rows} {config} x="month" syncId="months" />
<RadarChart data={rows} {config} x="month" syncId="months" />
<!-- syncMethod value: matched by the browser's name, not its position -->
<PieChart data={browsers} {config} value="visitors" name="browser" syncId="browsers" syncMethod="value" />
<RadialChart data={reversed} {config} value="visitors" name="browser" syncId="browsers" syncMethod="value" />

In a dialog

Escape on a focused chart hides its tooltip and leaves the dialog open; the next Escape closes the dialog.

Code
<Dialog title="Traffic">
  <Button slot="trigger">Open chart</Button>
  <BarChart data={rows} {config} x="month" />
</Dialog>
<!-- Escape on the focused chart hides its tooltip; the next Escape closes the dialog -->

Tooltip - Motion

animationDuration and animationEasing time how the tooltip follows the pointer; isAnimationActive false moves it at once.

JanFebMarAprMayJun
Bar chart
MonthDesktopMobile
January18680
February305200
March237120
April73190
May209130
June214140
JanFebMarAprMayJun
Bar chart
MonthDesktopMobile
January18680
February305200
March237120
April73190
May209130
June214140
Code
<!-- the tooltip glides 600ms with a linear easing; the second moves at once -->
<BarChart data={rows} {config} x="month" tooltip={{ animationDuration: 600, animationEasing: "linear" }} />
<BarChart data={rows} {config} x="month" tooltip={{ isAnimationActive: false }} />

Data table

Every chart carries its data as a table: visually hidden, read by screen readers, shown with showTable.

MonTueWedThuFriSat
Calories by activity
DateRunningSwimming
2024-07-15450300
2024-07-16380420
2024-07-17520120
2024-07-18140550
2024-07-19600350
2024-07-20480400
Code
<BarChart data={rows} {config} x="month" showTable={state.table} />
Reference Chart in the manual Every part, attribute, slot, key and data attribute.
Prev BarChartNext DataTable
Product
Manual Pricing Compare
Company
History Contact
Legal
Privacy Policy Acceptable Use Terms License Agreement
© Elements Dev Corporation 2026