Usage
Chart is a framework-independent Lit implementation of the compositional design used by shadcn-vue Chart. A Chart owns data and shared series configuration; axes, marks, tooltip, crosshair and legend are separate custom elements that describe what to render.
Import Chart and only the parts used by the composition. Each import registers one custom element:
import "@nordhealth/components/lib/Chart"
import "@nordhealth/components/lib/ChartAxis"
import "@nordhealth/components/lib/ChartLine"
import "@nordhealth/components/lib/ChartTooltip"
import "@nordhealth/components/lib/ChartCrosshair"
import "@nordhealth/components/lib/ChartLegend"
Other marks have their own entries, so a grouped bar chart can import ChartGroupedBar without importing ChartStackedBar, ChartLine, ChartArea, ChartPie or ChartDonut.
import "@nordhealth/components/lib/ChartArea"
import "@nordhealth/components/lib/ChartDonut"
import "@nordhealth/components/lib/ChartGroupedBar"
import "@nordhealth/components/lib/ChartPie"
import "@nordhealth/components/lib/ChartStackedBar"
Chart uses Unovis internally for rendering. You do not need to install or import Unovis. After a connected Chart has a label, data, config and valid composition, it lazily loads only the Unovis container, marks and helpers required by that composition. Importing Chart or another Nord component does not load the renderer. If the composition changes while loading is pending, Chart discards that stale request and renders only the latest valid revision.
Then compose the parts inside a Chart:
Composition
A Chart contains either one or more Cartesian marks, or one circular mark. Cartesian compositions can add axes, a tooltip, a crosshair and a legend. Circular compositions can add a tooltip and legend, but not axes or a crosshair. The required label becomes the accessible name of the rendered figure.
Chart
├── ChartAxis × 0–2 (Cartesian only)
├── ChartGroupedBar | ChartStackedBar (Cartesian marks)
│ | ChartLine | ChartArea
├── ChartPie | ChartDonut × 1 (circular alternative)
├── ChartTooltip × 0–1
├── ChartCrosshair × 0–1 (Cartesian; requires tooltip)
├── ChartLegend × 0–1
├── summary slot (complete accessible alternative)
└── empty slot (empty-data content)
Chart follows shadcn's configuration model. Assign a JavaScript-only .config record whose keys identify series or circular categories. Each item can provide a label, Nord icon name and either one color or a light/dark theme pair. TypeScript consumers can import the exported ChartConfig type from @nordhealth/components.
Items without a configured color use a theme-aware 17-color palette for Cartesian series or a five-color segmentation palette for pie and donut categories. Customize the defaults with --n-chart-color-1 through --n-chart-color-17 and --n-chart-segmentation-color-1 through --n-chart-segmentation-color-5.
const config = {
desktop: {
label: "Desktop",
theme: {
light: "var(--n-color-accent)",
dark: "var(--n-color-status-highlight)",
},
},
mobile: {
label: "Mobile",
color: "var(--n-color-status-info)",
},
}
Compose the visible structure in HTML. Functions and arrays are JavaScript properties, so assign them after creating plain custom elements or use the property-binding syntax provided by Lit, Vue, React, Angular or another framework.
<nord-chart label="Monthly visits">
<nord-chart-axis type="x" label="Month"></nord-chart-axis>
<nord-chart-axis type="y" label="Visits"></nord-chart-axis>
<nord-chart-line></nord-chart-line>
<nord-chart-tooltip></nord-chart-tooltip>
<nord-chart-crosshair></nord-chart-crosshair>
<nord-chart-legend></nord-chart-legend>
<table slot="summary"><!-- Complete data table. --></table>
<p slot="empty">No visits available.</p>
</nord-chart>
Assign the shared config and immutable rows, then pass direct accessors to the mark and helpers. Reassign a new data array whenever rows change; in-place mutations are not observed.
const chart = document.querySelector("nord-chart")
const line = chart.querySelector("nord-chart-line")
const xAxis = chart.querySelector('nord-chart-axis[type="x"]')
const tooltip = chart.querySelector("nord-chart-tooltip")
const month = row => row.month
const desktop = row => row.desktop
const mobile = row => row.mobile
chart.config = config
chart.data = [
{ month: "January", desktop: 186, mobile: 80 },
{ month: "February", desktop: 305, mobile: 200 },
]
line.x = month
line.y = [desktop, mobile]
line.keys = ["desktop", "mobile"]
xAxis.x = month
tooltip.label = month
For a single series, .y can be one accessor instead of an array. When .keys is omitted, Chart pairs the first config key with a single y accessor, or the first N config keys with N accessors. Explicit keys must exist in config and match the accessor count. A mark's optional .color property overrides config colors for that mark only.
Invalid compositions fail closed before Unovis loads and report stable NORD_CHART_* errors once per unchanged revision. The individual entries are SSR-safe and do not evaluate the renderer or read browser globals when imported.
Examples
Grouped bars
Chart Grouped Bar compares multiple values side by side. Assign one .x accessor, one .y accessor or accessor array, and optional matching .keys. Bars default to the 3px radius of --n-border-radius-s and 0.02 (2%) fractional padding; set rounded-corners, bar-padding, and group-padding to tune their shape and spacing. Set orientation="horizontal" when values should extend inline from each category.
Chart Axis requires type="x" or type="y". Assign the matching .x or .y accessor when an explicit scale is needed; an x axis otherwise inherits the first mark's x accessor. Use .tickValues and .tickFormat to customize ticks, hide-grid-lines to remove its grid and label for the visible title.
Stacked bars
Chart Stacked Bar displays each series as a contribution to a total. It uses the same .x, .y, .keys, .color, orientation, rounded-corners and bar-padding contract as grouped bars, but has a separate import so grouped and stacked code are never loaded together unless both are used. A one-row stacked composition with orientation="horizontal" creates a single proportionally split bar.
Line chart
Chart Line shows change over an ordered Cartesian scale. Assign .x, .y and optional .keys directly; config supplies the corresponding labels, icons and colors. Add show-points to render a marker at every data value. Its small Scatter renderer module is loaded only for line compositions that request points.
Chart Tooltip adds supplementary pointer content using config metadata. Its optional .label accessor supplies the heading, while .labelFormatter and .valueFormatter format safe text. Choose a dot, line or dashed indicator, or use hide-label and hide-indicator. A successful formatter result of null or undefined omits that content, numeric zero is preserved, and a throwing formatter falls back to the raw value.
Chart Crosshair adds Cartesian pointer interaction and requires a Chart Tooltip.
Area chart
Chart Area emphasizes magnitude as well as change. It uses the same .x, .y, .keys and .color properties as Chart Line. Set opacity between 0 and 1, and add hide-line to remove the area boundary.
Pie chart
Chart Pie shows a small part-to-whole comparison. Assign a .category accessor that returns a config key and a numeric .value accessor. Config insertion order controls stable labels, icons and colors unless the mark supplies a .color override.
Chart Legend renders config items as a semantic list. Use placement="block-start" to move it above the plot, hide-icons to remove icons and swatches, or assign .keys to show a subset in a specific order. Add toggleable to render accessible toggle buttons that show or hide a series; Chart always keeps at least one series visible. When config omits a color, Chart assigns --n-chart-color-1 through --n-chart-color-8 in stable config order.
Donut chart
Chart Donut uses the same .category, .value and .color properties as Chart Pie. It additionally requires a positive arc-width; central-label and central-sub-label add text to its centre.
Accessibility
- Give every Chart a concise, non-empty
labelso its figure has an accessible name. - Add prose or a semantic
<table slot="summary">containing every category, series and value represented visually. Theemptyslot provides content when.datahas no rows. - Treat the tooltip, crosshair and legend as supplementary; they are not replacements for the complete summary.
- Keep visible config labels and the summary so color is never the only carrier of meaning.
- When
prefers-reduced-motion: reducematches, Chart uses zero-duration animation for initial rendering, data updates and structural replacements. - Chart fills its available inline size and follows the active Nord color scheme. Reassign
.datato publish an update without rebuilding the composition. - Chart does not perform aggregation or downsampling. Prepare dense data before assignment, preserve important extrema and total meaning, and include the summarized values in the accessible table.
Templates
See this component composed into complete application views:
API reference
Chart
Chart owns a renderer-independent declarative chart composition.
<nord-chart></nord-chart>Props
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
label | label | Required non-empty accessible name for the visualization. | string | '' |
Slots
| Slot name | Description |
|---|---|
Default slot | Axis, mark, tooltip, crosshair, and legend parts. |
empty | Content shown instead of the visualization when data is empty. |
summary | A visually hidden complete prose or tabular alternative. |
CSS Properties
CSS Custom Properties provide more fine grain control over component presentation. We advise utilizing existing properties on the component before using these.
| Property | Description | Default |
|---|---|---|
--n-chart-block-size | Explicit block size of the chart plot. | auto |
--n-chart-min-block-size | Minimum block size of the chart. | 16rem |
--n-chart-color-1 | Default first series color. | var(--n-color-accent) |
--n-chart-color-2 | Default second series color. | var(--n-color-status-success) |
--n-chart-color-3 | Default third series color. | var(--n-color-status-danger) |
--n-chart-color-4 | Default fourth series color. | var(--n-color-status-progress) |
--n-chart-color-5 | Default fifth series color. | var(--n-color-status-warning) |
--n-chart-color-6 | Default sixth series color. | var(--n-color-status-info) |
--n-chart-color-7 | Default seventh series color. | var(--n-color-status-notification) |
--n-chart-color-8 | Default eighth series color. | var(--n-color-text-success) |
--n-chart-color-9 | Default ninth series color. | var(--n-color-status-highlight) |
--n-chart-color-10 | Default tenth series color. | var(--n-color-text-warning) |
--n-chart-color-11 | Default eleventh series color. | var(--n-color-text-info) |
--n-chart-color-12 | Default twelfth series color. | var(--n-color-text-danger) |
--n-chart-color-13 | Default thirteenth series color. | var(--n-color-text-progress) |
--n-chart-color-14 | Default fourteenth series color. | var(--n-color-text-highlight) |
--n-chart-color-15 | Default fifteenth series color. | var(--n-color-border-warning) |
--n-chart-color-16 | Default sixteenth series color. | var(--n-color-text-link) |
--n-chart-color-17 | Default seventeenth series color. | var(--n-color-text-weaker) |
--n-chart-segmentation-color-1 | Default first circular segment color. | var(--n-color-border-highlight) |
--n-chart-segmentation-color-2 | Default second circular segment color. | var(--n-color-accent) |
--n-chart-segmentation-color-3 | Default third circular segment color. | var(--n-color-status-highlight) |
--n-chart-segmentation-color-4 | Default fourth circular segment color. | var(--n-color-text-progress) |
--n-chart-segmentation-color-5 | Default fifth circular segment color. | var(--n-color-text-link) |
Parts
This component is made up of the following parts.
Chart Area
Chart Area emphasizes magnitude as well as change.
<nord-chart-area></nord-chart-area>Props
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
opacity | opacity | Area fill opacity. | number | 0.4 |
hideLine | hide-line | Hides the area boundary line. | boolean | false |
Chart Axis
Chart Axis describes one Cartesian axis.
<nord-chart-axis></nord-chart-axis>Props
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
type | type | Direction of the axis. | ChartAxisDirection | undefined | — |
hideGridLines | hide-grid-lines | Hides the axis grid lines. | boolean | false |
label | label | Optional human-readable axis label. | string | undefined | — |
Chart Crosshair
Chart Crosshair enables the supported Cartesian crosshair interaction.
<nord-chart-crosshair></nord-chart-crosshair>Chart Donut
Chart Donut shows a part-to-whole comparison around a centre.
<nord-chart-donut></nord-chart-donut>Props
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
arcWidth | arc-width | Positive width of the donut arc. | number | undefined | — |
centralLabel | central-label | Optional text displayed in the donut centre. | string | undefined | — |
centralSubLabel | central-sub-label | Optional secondary text displayed in the donut centre. | string | undefined | — |
Chart Grouped Bar
Chart Grouped Bar compares multiple values side by side.
<nord-chart-grouped-bar></nord-chart-grouped-bar>Props
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
roundedCorners | rounded-corners | Radius applied to bar corners. | number | 3 |
orientation | orientation | Direction in which values extend from their category. | ChartBarOrientation | 'vertical' |
barPadding | bar-padding | Fractional spacing between bars in a group. | number | 0.1 |
groupPadding | group-padding | Optional spacing between groups. | number | undefined | — |
Chart Legend
Chart Legend configures semantic legend presentation for a Chart.
<nord-chart-legend></nord-chart-legend>Props
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
placement | placement | Places the legend before or after the Chart plot. | ChartLegendPlacement | 'block-end' |
hideIcons | hide-icons | Hides decorative series icons and color swatches. | boolean | false |
toggleable | toggleable | Allows people to show and hide individual series. | boolean | false |
Chart Line
Chart Line shows change over an ordered Cartesian scale.
<nord-chart-line></nord-chart-line>Props
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
showPoints | show-points | Shows a marker at every rendered data value. | boolean | false |
Chart Pie
Chart Pie shows a small part-to-whole comparison.
<nord-chart-pie></nord-chart-pie>Chart Stacked Bar
Chart Stacked Bar compares contributions to a total.
<nord-chart-stacked-bar></nord-chart-stacked-bar>Props
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
roundedCorners | rounded-corners | Radius applied to bar corners. | number | 3 |
orientation | orientation | Direction in which values extend from their category. | ChartBarOrientation | 'vertical' |
barPadding | bar-padding | Fractional spacing between bars. | number | 0.1 |
Chart Tooltip
Chart Tooltip configures supplementary pointer content.
<nord-chart-tooltip></nord-chart-tooltip>Props
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
indicator | indicator | Indicator displayed beside each value. | ChartTooltipIndicator | 'dot' |
hideLabel | hide-label | Hides the tooltip heading. | boolean | false |
hideIndicator | hide-indicator | Hides value indicators. | boolean | false |
Dependencies
This component is internally dependent on the following components:
Design guidelinesFor designers
Usage
This section includes guidelines for designers and developers about the usage of this component in different contexts.
Do
- Choose a chart form that matches the question: bars for discrete comparisons, lines or areas for change over time, and pie or donut charts for a small part-to-whole comparison.
- Keep the chart responsive and provide a concise visible context around it.
- Name every series in the legend and provide an equivalent semantic summary table containing the complete data.
- Format values and axes with the same units and precision used elsewhere in the product.
- Treat formatter exceptions as recoverable display failures: Chart reports the first error for that formatter and series, then falls back to the raw value.
- Aggregate or downsample dense data before rendering it.
Don’t
- Don’t use color, a tooltip, or pointer interaction as the only way to communicate information.
- Don’t show a pie or donut with many similar slices; use a sorted bar chart or table instead.
- Don’t imply precision that the source data does not have.
- Don’t put raw, unbounded event streams into a chart. Summarize large data sets for the decision the chart supports.
Chart is currently alpha. Confirm its API and visual output when upgrading Nord.