I am using react-d3-components for D3 chart. i am successfully generating the Bar chart. but my requirement is to generate horizontal bar chart
var React = require('react');
var ReactDOM = require('react-dom');
var d3 = require('d3');
var BarChart = require('react-d3-components').BarChart;
var data = [{
label: 'somethingA',
values: [{x: 'SomethingA', y: 10}, {x: 'SomethingB', y: 4}, {x: 'SomethingC', y: 3}]
}];
ReactDOM.render(
<BarChart
data={data}
width={400}
height={400}
margin={{top: 10, bottom: 50, left: 50, right: 10}}/>,
document.getElementById('root')
);

And i need output horizontal bar chart.

I achieved this by following this tutorial: https://medium.com/@caspg/responsive-chart-with-react-and-d3v4-afd717e57583
I then swapped the x axis and y axis details around. So in our case the y axis will be scaleBand() and the x axis is scaleLinear()
I also swapped the width and height of the bars in the Bars component to get the correct orientation of the bars.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With