问题
Custom label for React Recharts not working with Bar chart.
http://jsfiddle.net/xpko4e7e/
<Bar dataKey="pv" fill="#8884d8" label={<CustomLabel/>} />
Expected to see the 'Label' text over of all bars.
回答1:
instead of returning a div try returning a text SVG element
const CustomizedLabel = React.createClass({
render () {
const {x, y, stroke, value} = this.props;
return <text x={x} y={y} dy={-4} fill={stroke} fontSize={10} textAnchor="middle">{value}</text>
}
});
and then add
<Bar dataKey="pv" fill="#8884d8" label={customLabel} />
like I have done here, http://jsfiddle.net/CharukaK/6u08o2oa/1/
来源:https://stackoverflow.com/questions/42012019/recharts-custom-label