I want to display string or numeric value above each rect(bar) element in VerticalBarSeries of react-vis. And value should be just above the bar height. Also, How can I change bar height,width and margin of barSeries. I have used display: flex to make multiply bar chart appear next to each is there any another way to do it? Below is my code:
import React from 'react';
import {
XYPlot,
XAxis,
YAxis,
makeVisFlexible,
makeWidthFlexible,
makeHeightFlexible,
VerticalBarSeries,
VerticalBarSeriesCanvas
} from 'react-vis';
const myDATA = [
{ y: 100, x: "Jan" },
{ y: 112, x: "Feb" },
{ y: 230, x: "Mar" },
{ y: 250,x: "Apr" },
{ y: 270,x: "grbd" },
];
const yDomain = myDATA.reduce(
(res, row) => {
return {
max: Math.max(res.max, row.y),
min: Math.min(res.min, row.y)
};
},
{max: -Infinity, min: Infinity}
);
export default class Example extends React.Component {
state = {
useCanvas: false
};
render() {
const FlexibleXYPlot = makeVisFlexible(XYPlot);
const FlexibleWidthXYPlot = makeWidthFlexible(XYPlot);
const FlexibleHeightXYPlot = makeHeightFlexible(XYPlot);
const data = myDATA;
const chartWidth = 150;
const chartHeight = 300;
const chartDomain = [0, chartHeight]
return (
<div style={{display: 'flex'}}>
<FlexibleXYPlot
xType="ordinal"
width={chartWidth}
height={chartHeight}
yDomain={chartDomain}
style={{float: 'left'}}
margin={{left: 40, right: 10, top: 10, bottom: 40}}
>
<VerticalBarSeries
data={data}
/>
</FlexibleXYPlot>
<XYPlot
xType="ordinal"
width={chartWidth}
height={chartHeight}
yDomain={chartDomain}
style={{float: 'left'}}
>
<VerticalBarSeries
data={data}
/>
</XYPlot>
<XYPlot
xType="ordinal"
width={chartWidth}
height={chartHeight}
yDomain={chartDomain}
float='left'
style={{float: 'left'}}
>
<VerticalBarSeries
data={data}
/>
</XYPlot>
</div>
)
}
}