gpt4 book ai didi

reactjs - 重新绘制自定义标签

转载 作者:行者123 更新时间:2023-12-03 13:29:10 25 4
gpt4 key购买 nike

React Recharts 的自定义标签不适用于条形图。

http://jsfiddle.net/xpko4e7e/

 <Bar dataKey="pv"  fill="#8884d8"  label={<CustomLabel/>} />

预计会在所有栏上看到“标签”文本。

更新
例如,如果我有一个图表,其中有多条线,并且每条线都有一些标签,但在渲染时,某些值高于另一个值。如何克服这个问题?

Image Preview

最佳答案

尝试返回文本 SVG 元素,而不是返回 div

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>
}
});

然后添加

<Bar dataKey="pv"  fill="#8884d8"  label={customLabel} />

就像我在这里所做的那样,http://jsfiddle.net/CharukaK/6u08o2oa/1/

关于reactjs - 重新绘制自定义标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42012019/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com