@vtex/styleguide
Version:
> VTEX Styleguide React components ([Docs](https://vtex.github.io/styleguide))
91 lines (77 loc) • 2.29 kB
Markdown
```js
const data = require('./sampleData').default;
<BarChart
data={data}
xAxisKey='name'
yAxisKey='pv'
config={{
container: { height: '100%', width: '100%'}
}}
/>
```
- Start at the zero baseline.
- Rotate bar labels
- Use bar chart like an histogram
The bars can be plotted horizontally or vertically. To do this, use the prop `barProps` and set the `layout` key, according do you want. In recharts, the things are switched, so take careful with this.
- Horizontal: `{layout: 'vertical'}`
```js
const data = require('./sampleData').default;
const CustomizedLabel = (props) => {
const {
x, y, fill, payload,
} = props
const value = (typeof payload.value) == 'string' ?
payload.value.split(' ')[0]: payload.value
return (
<text x={x/16} y={y} fill={fill} fontSize={14}>
{value}
</text>
)
};
<BarChart
data={data}
xAxisKey='pv'
yAxisKey='name'
config={{
container: { height: '60%', width: '60%'},
xAxis: {type: 'number'},
yAxis: {type: 'category', tick: <CustomizedLabel/>}
}}
barProps={{layout: 'vertical'}}
/>
```
- Vertical: `{layout: 'horizontal'}`
```js
const data = require('./sampleData').default;
<BarChart
data={data}
xAxisKey='name'
yAxisKey='pv'
config={{
container: {height: '60%', width: '60%'},
xAxis: {type: 'category'},
yAxis: {type: 'number'}
}}
barProps={{layout: 'horizontal'}}
/>
```
**OBS:** To correctly change the orientation, set both axis types.
For default, xAxis is a `category` and yAxis is a `number`
```js static
<BarChart
data={data}
xAxisKey='name'
yAxisKey='pv'
config={{
xAxis: {type: 'category'},
yAxis: {type: 'number'}
}}
barProps={{layout: 'horizontal'}}
/>
```
You also can change the axis, grid and the size of the container like the `LineChart`. Follow the same instructions, described [here](/