Charts - Range Bar
Use range bar charts to show the span between minimum and maximum values across categories.
Overview
A range bar chart displays the span between two values for each category.
Each bar extends from a lower to an upper value. This chart type works well for visualizing data like temperature ranges, project timelines, or performance intervals.
Basics
To create a range bar chart, render BarChartPremium with at least one series of type 'rangeBar'.
Each data point in a range bar series consists of a { start: number, end: number } object.
Average monthly temperature ranges in °C for Porto and Berlin in 1991-2020
- Porto, Portugal
- Berlin, Germany
Using a dataset
You can use the dataset prop combined with datasetKeys or valueGetter on the series to extract range values from dataset items.
See the Dataset page for more details.
Customization
Grid
You can add a grid in the background of the chart with the grid prop.
See Axis—Grid for details.
Border radius
To achieve rounded corners, set the borderRadius prop on BarChartPremium to any positive value.
When composing a custom component, set the borderRadius prop on the RangeBarPlot component.
Border Radius
<BarChartPremium
// ...
borderRadius={10}
/>Color
You can set series colors for individual series or use the color palette.
Use a colorMap to map values to colors.
The color set by colorMap has priority over other color settings.
See Styling—Value-based colors for more details on colorMap.
<BarChart
/* ... */
xAxis={[{
colorMap: {
type: 'piecewise',
thresholds: [new Date(2021, 1, 1), new Date(2023, 1, 1)],
colors: ['blue', 'red', 'blue'],
}
}]}
/>CSS
You can customize the range bar chart elements using CSS selectors.
Like a bar chart, each series renders a g element that contains a data-series attribute.
You can use this attribute to target elements based on their series.
Labels
You can display labels on the range bars.
If you provide 'value' to the barLabel property of a range bar series, the range of that bar is shown as start – end.
Alternatively, the barLabel property accepts a function that is called with the range bar item and context about the bar.
To customize the position of the label, set a series' barLabelPlacement property to one of the following values:
center: the label is centered on the bar.outside: the label is placed after the end of the range, from the point of view of its start. For a vertical range bar whose end is greater than its start, the label is above its top edge.
- Center
- Outside
Custom labels
To display, change, or hide labels based on conditional logic, provide a function to the barLabel property.
Labels are not displayed if the function returns null.
The example below displays the temperature amplitude of each month and hides labels when the bar height is lower than 90px.
- Porto, Portugal
Click event
The click event handlers work similarly to bar charts. See Bars—Click events for details.
- A
- B
Click on the chart
// Data from item click
// The data will appear here
// Data from axis click
// The data will appear hereAnimation
Animation works similarly to bar charts. See Bars—Animation for details.
- series 1
- series 2
Number of items
Number of series
Performance
For larger datasets, BarChartPremium supports a WebGL renderer that draws all range bars from a single <canvas> element.
Set the renderer prop to "webgl" to enable it.
The same trade-offs as the bar chart WebGL renderer apply.
- Series A
- Series B
Composition
Use ChartDataProviderPremium to provide series, xAxis, and yAxis props for composition.
In addition to the shared chart components available for composition, you can render the RangeBarPlot component to display the range bars and their labels.
The example below shows how BarChartPremium is composed:
<ChartsDataProviderPremium>
<ChartsWrapper>
<ChartsLegend />
<ChartsSurface>
<ChartsGrid />
<g clipPath={`url(#${clipPathId})`}>
<BarPlot />
<RangeBarPlot />
<ChartsOverlay />
<ChartsAxisHighlight />
<FocusedBar />
<FocusedRangeBar />
</g>
<ChartsAxis />
<ChartsClipPath id={clipPathId} />
</ChartsSurface>
<ChartsTooltip />
</ChartsWrapper>
</ChartsDataProviderPremium>
The example below follows a similar pattern and creates a project schedule chart using range bars to represent task durations.
API
See the documentation below for a complete reference to all of the props and classes available to the components mentioned here.