Skip to main content

Spectrum 2 Overview

Work in progress

Spectrum 2 support in React Spectrum Charts is actively under development. The S2 package still has some Spectrum 1 dependencies that are being incrementally migrated. We will make an effort not to introduce breaking API changes to Spectrum 2 features prior to Adobe Summit.

React Spectrum Charts offers two paths for Spectrum 2 support. This page explains the difference between them, how to install the full S2 package, and how theming works.

S2 prop vs. the S2 package

s2 prop (partial S2 support)

The @adobe/react-spectrum-charts package includes an s2 prop on the Chart component. When set to true, it enables Spectrum 2 styling for supported chart types. Currently supported: Line, Bar, and Donut.

import { Chart, Bar } from '@adobe/react-spectrum-charts';

<Chart data={data} s2>
<Bar color="series" />
</Chart>

Use this approach if you are already using @adobe/react-spectrum-charts and only need S2 theming for supported chart types.

@spectrum-charts/react-spectrum-charts-s2 package (full S2 support)

The S2 package is a separate alpha package built entirely on Spectrum 2. It provides a full S2-native implementation of the chart library with additional features not available in the base package. All components are imported from this package instead of @adobe/react-spectrum-charts.

Use this approach when you need access to S2-exclusive features such as line gradients, line labels, line interpolation, or S2 reference lines.


Installing the S2 package

The S2 package is published under the alpha tag on npm.

npm install @spectrum-charts/react-spectrum-charts-s2@alpha
# or
yarn add @spectrum-charts/react-spectrum-charts-s2@alpha

Import components from the S2 package instead of the base package:

import { Chart, Axis, Line, Legend } from '@spectrum-charts/react-spectrum-charts-s2';

The S2 package requires @adobe/react-spectrum as a peer dependency for its popover and tooltip components:

npm install @adobe/react-spectrum

Theming

Color scheme

The Chart component accepts a colorScheme prop to switch between light and dark mode. This controls both the chart's visual theme and the styling of tooltips and popovers.

<Chart data={data} colorScheme="dark">
<Line color="series" />
</Chart>
ValueDescription
'light'Light mode (default)
'dark'Dark mode

Colors

The S2 package uses Spectrum 2 categorical color scales by default. You can override the color scale using the colors prop on Chart.

Available S2 color scales: s2Categorical6, s2Categorical12, s2Categorical16, s2Categorical20.

<Chart data={data} colors="s2Categorical12">
<Line color="series" />
</Chart>

Tooltips

Tooltips in the S2 package are styled automatically to match the Spectrum 2 design specification — including the correct font (adobe-clean), text colors, border, and elevated box shadow. No additional configuration is required.

Add a ChartTooltip as a child of a mark component to enable tooltips:

<Line color="series">
<ChartTooltip>
{(datum) => (
<div>
<div>Series: {datum.series}</div>
<div>Value: {datum.value}</div>
</div>
)}
</ChartTooltip>
</Line>

Popovers

Popovers are styled to match the Spectrum 2 elevated surface style (border, box shadow, font). Add a ChartPopover as a child of a mark component to enable click-to-open popovers:

<Line color="series">
<ChartPopover width={200}>
{(datum, close) => (
<div>
<div>Series: {datum.series}</div>
<div>Value: {datum.value}</div>
<button onClick={close}>Close</button>
</div>
)}
</ChartPopover>
</Line>

ChartTooltip props

nametypedefaultdescription
children(datum: Datum) => ReactNodeCallback that returns the content to render inside the tooltip.
excludeDataKeysstring[]Keys in the data that, if they have truthy values, will suppress the tooltip for that data point.
highlightBy'series' | 'dimension' | 'item' | string[]'item'Controls which marks are highlighted when a tooltip is visible.
targets('dimensionArea' | 'item')[]['item']The hit targets that trigger the tooltip.

ChartPopover props

nametypedefaultdescription
children(datum: Datum, close: () => void) => ReactNodeCallback that returns the content to render inside the popover. The second argument is a function that closes the popover.
widthnumber | 'auto'250Width of the popover in pixels, or 'auto' to size to content.
minWidthnumber0Minimum width of the popover in pixels.
maxWidthnumberMaximum width of the popover in pixels.
heightnumber | 'auto'Height of the popover in pixels.
minHeightnumberMinimum height of the popover in pixels.
maxHeightnumberMaximum height of the popover in pixels.
contentMarginnumber12Inner margin applied around the popover content in pixels.
onOpenChange(isOpen: boolean) => voidCallback fired when the popover opens or closes.
rightClickbooleanfalseWhen true, the popover opens on right-click instead of left-click.
containerPaddingnumber12Minimum distance between the popover and the edges of its container.