BarChart component for Stripe Apps
A bar chart visualizes data as a series of data points using bars.
To add the BarChart
component to your app:
import {BarChart} from '@stripe/ui-extension-sdk/ui';
The following shows a preview of the BarChart
UI component:
const sales = [ { date: 'Jan', sold: 1, }, { date: 'Feb', sold: 4, }, { date: 'Mar', sold: 2, }, { date: 'Apr', sold: 3, }, ]; return ( <Box css={{width: 'fill'}}> <BarChart data={sales} x="date" y="sold" /> </Box> )
BarChart props![](https://b.stripecdn.com/docs-statics-srv/assets/fcc3a1c24df6fcffface6110ca4963de.svg)
Property | Type |
---|---|
| Required
The data used to generate the chart. |
| Required
The property or accessor for the point on the x axis. Related types: Channel. |
| Required
The property or accessor for the point on the y axis. Related types: Channel. |
| Optional
Determines whether to render labels and ticks for each axis. |
| Optional
Groups data by color based on a property or accessor. Related types: Channel. |
| Optional
Determines whether to render grid lines for each axis. |
| Optional
Determines whether to render the legend (when more than one item is present). |
| Optional
Determines whether to render a tooltip when hovering over the chart. |
| Optional
Groups data based on a property or accessor. Related types: Channel. |
Channel![](https://b.stripecdn.com/docs-statics-srv/assets/fcc3a1c24df6fcffface6110ca4963de.svg)
Property | Type |
---|---|
| Optional
|
| Optional
Related types: Currency, UnitIdentifier. |
| Optional
|
| Optional
|
Currency![](https://b.stripecdn.com/docs-statics-srv/assets/fcc3a1c24df6fcffface6110ca4963de.svg)
Property | Type |
---|---|
| Required
|
UnitIdentifier![](https://b.stripecdn.com/docs-statics-srv/assets/fcc3a1c24df6fcffface6110ca4963de.svg)
Property | Type |
---|---|
| Required
|
Using color![](https://b.stripecdn.com/docs-statics-srv/assets/fcc3a1c24df6fcffface6110ca4963de.svg)
The color
channel groups data:
const sales = [ { date: 'Jan', sold: 1, product: 'tables', }, { date: 'Jan', sold: 2, product: 'chairs', }, { date: 'Feb', sold: 4, product: 'tables', }, { date: 'Feb', sold: 6, product: 'chairs', }, { date: 'Mar', sold: 2, product: 'tables', }, { date: 'Mar', sold: 4, product: 'chairs', }, { date: 'Apr', sold: 7, product: 'tables', }, { date: 'Apr', sold: 9, product: 'chairs', }, ]; return ( <Box css={{width: 'fill'}}> <BarChart data={sales} x="date" y="sold" color="product" /> </Box> )
Axis and value formatting![](https://b.stripecdn.com/docs-statics-srv/assets/fcc3a1c24df6fcffface6110ca4963de.svg)
Instead of passing a string for an axis value, you can add richer formatting by passing an object including the value
, label
and/or format
properties.
Property | Type |
---|---|
|
The property name in the data set. Required. |
|
The display text for the axis. |
|
Format a number with one of the supported currency codes for example |
<Box css={{width: 'fill'}}> <BarChart data={[ { date: 'January', sold: 10, }, { date: 'February', sold: 41, }, { date: 'March', sold: 22, }, { date: 'April', sold: 38, }, ]} x="date" y={{value: 'sold', label: 'Price', format: {currency: 'USD'}}} /> </Box>
Domain![](https://b.stripecdn.com/docs-statics-srv/assets/fcc3a1c24df6fcffface6110ca4963de.svg)
To set the minimum and maximum values of an axis, use the domain
prop. For example, if you always want the y
axis to go from 0 to 10 (rather than automatically adjusting to the data provided), add the domain
property to your configuration:
const sales = [ { date: 'Jan', sold: 1, }, { date: 'Feb', sold: 4, }, { date: 'Mar', sold: 2, }, { date: 'Apr', sold: 3, }, ]; return ( <Box css={{width: 'fill'}}> <BarChart data={sales} x="date" y={{value: 'sold', label: 'Sold', domain: [0, 10]}} /> </Box> )