reactjs - 如何在 Recharts React 中手动标记 LabelList
问题描述
我想像这样手动命名水平条形图中的条形
<Bar dataKey="performanceavg" fill="#FFB85F">
<LabelList dataKey="performanceavg" position="insideRight" />
<LabelList content={"Performance Average"} position="insideLeft" />
</Bar>
测试了这个的不同变体,但遗憾的是没有成功。
我让它使用这个 http://recharts.org/en-US/examples/BarChartWithMinHeight
<Bar dataKey="performanceavg" fill="#FFB85F">
<LabelList dataKey="performanceavg" position="insideRight" />
<LabelList content={this.renderCustomizedLabel} position="insideLeft" />
</Bar>
和
renderCustomizedLabel = (props) => {
console.log(props)
const { x, y, width, height, value } = props;
console.log(props)
return (
<g>
<text x={x} y={y + height/2}>Performance Average</text>
</g>
);
};
但这似乎很复杂,并且 y + height/2 不是中间值,但可能需要以某种方式使用字体的高度。一般来说,这对于简单的标签来说似乎很复杂
有没有更好的办法?
解决方案
啊像这样它工作:-)
<Bar dataKey="performanceavg" fill="#FFB85F">
<LabelList dataKey="performanceavg" position="insideRight" />
<LabelList position="insideLeft">Performance Average</LabelList>
</Bar>
推荐阅读
- android - 错误:无法解决:com.android.support.constraint:constraint-layout:28.0.0
- reactjs - 如何渲染我的模态窗口和里面包含的所有信息(在 React 中)?
- .net-core - 同一页面中的 Blazor 路由更改
- c++ - 如何从 boost::multi_index_container 中检索元素
- c++ - Arrayfire中的赋值问题
- windows - 如何使用批处理从具有多种日志类型的文件夹中复制每种类型文件中的两个最新文件
- java - 在屏幕上居中 Google 路线
- shopify - 需要有效的商店查询参数
- android - Android Q的公共路径
- javascript - 为什么即使使用换行标记,我的添加到购物车按钮也会出现在图像旁边而不是图像下方?