我正在使用recharts库创建一个水平条形图。我想在左侧对齐y轴标签。
<BarChart width={400} height={300} data={data} layout="vertical" margin={{right: 40}}>
<XAxis hide axisLine={false} type="number"/>
<YAxis dataKey="name" type="category" axisLine={false} tickLine={false} />
<Bar dataKey="pv" stackId="a" barSize={15} radius={[20,20,20,20]} fill="#8884d8" background={{fill: "#eee", radius: [20,20,20,20]}} tick={false} />
<Bar dataKey="uv" stackId="a" barSize={15} radius={[20,20,20,20]} fill="#eee" >
<LabelList dataKey="amt" position="right" />
</Bar>
</BarChart>发布于 2019-06-17 16:51:51
您可以通过使用自定义Tick组件来完成此操作。
const CustomYAxisTick = React.createClass({
render() {
const { x, y, payload } = this.props;
return (<g transform={`translate(${0},${y})`}>
<text x={0} y={0}
textAnchor="start"
fill="#666">{payload.value}</text>
</g>)
}
})然后你可以在你的YAxis中使用它:
<YAxis tick={<CustomYAxisTick />} />我派生了你的JSFiddle并添加了这些更改。
https://stackoverflow.com/questions/50834913
复制相似问题