Skip to main content

Data Selection

Victory allows multiple ways to select data points on a chart. VictorySelectionContainer is a container component that allows users to select data points within a region of a chart. Use VictoryBrushContainer to identify the domain of a selected region.

info

VictorySelectionContainer is similar to VictoryBrushContainer. VictoryBrushContainer may be used to identify the domain of a selected region, whereas VictorySelectionContainer may be used to identify a list of data points within a selected region. VictoryBrushContainer will also create persistent highlighted regions, whereas regions created by VictorySelectionContainer disappear after onMouseUp events.

VictorySelectionContainer

Use VictorySelectionContainer to add data selection behavior to any Victory components that work with an x-y coordinate system.

See the full API here.

Basic

VictorySelectionContainer may be used with any Victory component that works with an x-y coordinate system, and should be added as the containerComponent of the top-level component. However, the component that uses it must be standalone (standalone={true}), which is the default for all top-level Victory components.

Live View
Loading...
Live Editor

Active Points

The VictorySelectionContainer will automatically set an active prop on the data points that are within the selected region. This prop can be used to style the selected points differently.

Live View
Loading...
Live Editor

Selection Limits

The selectionDimension prop may be used to limit brushing behavior to a single dimension. In the example below, the selectionDimension prop is set to "y", allowing users to select a region of the chart along the y-axis only.

Live View
Loading...
Live Editor

Events

Use the onSelection prop to define a function that will be called with the selected domain when the selection area changes.

Live View
Loading...
Live Editor

VictoryBrushContainer

Use VictoryBrushContainer to add highlighting and selection to any Victory components that work with an x-y coordinate system.

See the full API here.

Basic

In the example below, the VictoryBrushContainer component is used to highlight a region of a line chart. The brush behavior is unconstrained by default, allowing users to click and drag to select a region of the chart.

Live View
Loading...
Live Editor

Selection Limits

The brushDimension prop may be used to limit brushing behavior to a single dimension. In the example below, the brushDimension prop is set to "y", allowing users to select a region of the chart along the y-axis only and the brushDomain restricts the highlighted area to the specified range.

Live View
Loading...
Live Editor

Events

VictoryBrushContainer exposes several events you can use to access the selection range. In the example below, you can monitor your browser's console to see the events in action.

Live View
Loading...
Live Editor