Skip to main content
LineChart
@coinbase/cds-web-visualization@3.4.0-beta.9
A flexible line chart component for displaying data trends over time. Supports multiple series, custom curves, areas, scrubbing, and interactive data exploration.
Import
import { LineChart } from '@coinbase/cds-web-visualization'
SourceView source code
Peer dependencies
  • framer-motion: ^10.18.0
View as Markdown

LineChart is a wrapper for CartesianChart that makes it easy to create standard line charts, supporting a single x/y axis pair. Charts are built using SVGs.

Basics

The only prop required is series, which takes an array of series objects. Each series object needs an id and a data array of numbers.

Loading...

LineChart also supports multiple lines, interaction, and axes. Other props, such as areaType can be applied to the chart as a whole or per series.

Loading...

Data

The data array for each series defines the y values for that series. You can adjust the y values for a series of data by setting the data prop on the xAxis.

Loading...

Live Updates

You can change the data passed in via series prop to update the chart.

You can also use the useRef hook to reference the scrubber and pulse it on each update.

Loading...

Missing Data

By default, null values in data create gaps in a line. Use connectNulls to skip null values and draw a continuous line. Note that scrubber beacons and points are still only shown at non-null data values.

Loading...

Empty State

Loading...

Scales

LineChart uses linear scaling on axes by default, but you can also use other types, such as log. See XAxis and YAxis for more information.

Loading...

Interaction

Charts have built in functionality enabled through scrubbing, which can be used by setting enableScrubbing to true. You can listen to value changes through onScrubberPositionChange. Adding Scrubber to LineChart showcases the current scrubber position.

Loading...

Points

You can use points from LineChart with onClick listeners to render instances of Point that are interactable.

Loading...

Animations

You can configure chart transitions using transition on LineChart and beaconTransitions on Scrubber. You can also disable animations by setting the animate on LineChart to false.

Loading...

Accessibility

You can use accessibilityLabel on both the chart and the scrubber to provide descriptive labels. The chart's label gives an overview, while the scrubber's label provides specific information about the current data point being viewed.

Loading...

When a chart has a visible header or title, you can use aria-labelledby to reference it, and still provide a dynamic scrubber accessibility label.

Loading...

Styling

Axes

Using showXAxis and showYAxis allows you to display the axes. For more information, such as adjusting domain and range, see XAxis and YAxis.

Loading...

Gradients

Gradients can be applied to the y-axis (default) or x-axis. Each stop requires an offset, which is based on the data within the x/y scale and color, with an optional opacity (defaults to 1).

Values in between stops will be interpolated smoothly using srgb color space.

Loading...

You can even pass in a separate gradient for your Line and Area components.

Loading...

Lines

You can customize lines by placing props in LineChart or at each individual series. Lines can have a type of solid or dotted. They can optionally show an area underneath them (using showArea).

Loading...

You can also add instances of ReferenceLine to your LineChart to highlight a specific x or y value.

Loading...

Points

You can also add instances of Point directly inside of a LineChart.

Loading...

Scrubber

When using Scrubber with series that have labels, labels will automatically render to the side of the scrubber beacon.

You can customize the line used for and which series will render a scrubber beacon.

You can have scrubber beacon's pulse by either adding idlePulse to Scrubber or use Scrubber's ref to dynamically pulse.

Loading...

Sizing

Charts by default take up 100% of the width and height available, but can be customized as any other component.

Loading...

Compact

You can also have charts in a compact form.

Loading...

Composed Examples

Asset Price with Dotted Area

You can use PeriodSelector to have a chart where the user can select a time period and the chart automatically animates.

Loading...

Monotone Asset Price

You can adjust YAxis and Scrubber to have a chart where the y-axis is overlaid and the beacon is inverted in style.

Loading...

Asset Price Widget

Loading...

Service Availability

You can have irregular data points by passing in data to xAxis.

Loading...

Forecast Asset Price

You can combine multiple lines within a series to change styles dynamically.

Loading...

Is this page useful?

Coinbase Design is an open-source, adaptable system of guidelines, components, and tools that aid the best practices of user interface design for crypto products.