gpt4 book ai didi

recharts - 我的图表中的自定义图例标签

转载 作者:行者123 更新时间:2023-12-04 01:39:16 25 4
gpt4 key购买 nike

我的图表组件有一个非常简单的数据数组:

{name: '12.1.2011', series1: 4000, series2: 2400, series3: 2400},
{name: '12.2.2011', series1: 3000, series2: 1398, series3: 2210},
{name: '12.3.2011', series1: 2000, series2: 9800, series3: 2290}


我想在我的图例中为系列值添加标签。而不是向我显示“ series1”,“ series2”和“ series3”的不同颜色的图表。

当然,我可以在JSON中设置要用于图例的实际值,但这看起来并不正确。例如:

{name: '12.1.2011', 'My nice long descriptive text': 4000, 'Some other text': 2400, 'Some other descriptive text': 2400},
{name: '12.2.2011', 'My nice long descriptive text': 3000, 'Some other text': 1398, 'Some other descriptive text: 2210},
{name: '12.3.2011', 'My nice long descriptive text': 2000, 'Some other text': 9800, 'Some other descriptive text: 2290}


我需要将系列级别映射到描述性标签。

我已经查看了Legend: http://recharts.org/#/en-US/api/Legend中的内容,但似乎与完全重写Legend组件有关。

最佳答案

LineBarArea中添加一个name属性。

例:

<Line name="# Apples" type="monotone" dataKey="series1" stroke="#FF0000" />
<Line name="# Bananas" type="monotone" dataKey="series2" stroke="#FFFF00" />
<Line name="# Grapes" type="monotone" dataKey="series3" stroke="#FF00FF" />


图例将自动进行处理:

http://recharts.org/en-US/api/Legend


默认情况下,图例的内容由Line名称生成,
条形图,区域等。未设置名称时,dataKey将用于
或者生成图例内容。

关于recharts - 我的图表中的自定义图例标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44413185/

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