Important: LayerChart v2 is still in pre-release and is actively evolving. Only use if you’re comfortable with potential breaking changes before stable v2.Your feedback will be invaluable in shaping the release and features. Current development status can be tracked here.
Component
We use LayerChart under the hood. We designed theChart component with composition in mind. You build your charts using LayerChart components and only bring in custom components, such as ChartTooltip, when and where you need it
Installation
- CLI
- Manual
Your First Chart
Let’s build your first chart. We’ll build a bar chart with an axis, grid, tooltip, and legend.Define your data
The following data represents the number of desktop and mobile users for each month.
Note: Your data can be in any shape. You are not limited to the shape of the data below. Use the
dataKey prop to map your data to the chart.lib/components/example-chart.svelte
Define your chart config
The chart config holds configuration for the chart. This is where you place human-readable strings, such as labels, icons, and color tokens for theming.
lib/components/example-chart.svelte
Chart Config
The chart config is where you define the labels, icons and colors for a chart. It is intentionally decoupled from chart data. This allows you to share config and color tokens between charts. It can also works independently for cases where your data or color tokens live remotely or in a different format.Theming
Charts has built-in support for theming. You can use css variables (recommended) or color values in any color format, such as hex, hsl, or oklch.CSS Variables
hex, hsl or oklch
You can also define your colors directly in the chart config. Use the color format you prefer.Using Colors
To use the theme colors in your chart, reference the colors using the formatvar(--color-KEY).
Components
Chart Data
Tailwind
Tooltip
A chart tooltip contains a label, name, indicator and value. You can use a combination of these to customize your tooltip. You can turn on/off any of these using thehideLabel, hideIndicator props and customize the indicator style using the indicator prop.
Use labelKey and nameKey to use a custom key for the tooltip label and name.
Chart comes with the <Chart.Tooltip> component. You can use this component to add custom tooltips to your chart.
Props
Use the following props to customize the tooltip.| Prop | Type | Description |
|---|---|---|
labelKey | string | The config or data key to use for the label. |
nameKey | string | The config or data key to use for the name. |
indicator | dot line or dashed | The indicator style for the tooltip. |
hideLabel | boolean | Whether to hide the label. |
hideIndicator | boolean | Whether to hide the indicator. |
label | string | A custom label for the tooltip |
labelFormatter | function | A function to format the label. |
formatter | Snippet | A snippet to provide flexible rendering of the tooltip. |
Colors
Colors are automatically referenced from the chart config.Custom
To use a custom key for tooltip label and names, use thelabelKey and nameKey props.
Total Visitors for label and Chrome and Safari for the tooltip names.