gpt4 book ai didi

recharts - 重新绘制散点图工具提示以显示附加 Prop

转载 作者:行者123 更新时间:2023-12-04 01:32:42 24 4
gpt4 key购买 nike

我正在使用 Rechart 的散点图

数据显示正常,但我想工具提示显示一个额外的弹出窗口(项目的名称),就像它在条形图上一样。我发现我可以完全自定义工具提示,但我想知道是否有更简单的方法?就像一个我不知道如何使用的 Prop 。 the doc关于如何使用一些 Prop 不是很明确

这是代码。你可以看到我已经尝试过数据键和标签,但没有成功

<ScatterChart
width={400}
height={400}
margin={{
top: 20, right: 20, bottom: 20, left: 20,
}}
>
<CartesianGrid />
<XAxis type="number" dataKey="sizeMB" name="Size" unit=" MB" />
<YAxis type="number" dataKey="directReferenceCount" name="# of References" unit=" References" />
<Tooltip cursor={{ strokeDasharray: '3 3' }} dataKey={'fullName'} label={'fullName'} />
<Scatter name="Line Item" data={this.props.data} fill="#8884d8">

</Scatter>
</ScatterChart>

最佳答案

除了使用完整的自定义工具提示之外,我没有找到解决方案。这是代码:

  const CustomTooltip = ({ active, payload, label }) => {
if (active) {
return (
<div className="custom-tooltip">
<p className="intro">{payload[0].payload.fullName}</p>
<p className="desc">size: {payload[0].payload.sizeMB}</p>
</div>
);
}

return null;
};

我在找到与原始工具提示相同的 css 时遇到了一些麻烦,但这里是:
.custom-tooltip{
margin: 0;
line-height: 24px;
border: 1px solid #f5f5f5;
background-color: rgba(255, 255, 255, 0.8);
padding: 10px;
}

.intro {
border-top: 1px solid #f5f5f5;
margin: 0;
}

.desc {
margin: 0;
color: rgb(3, 62, 146)
}

关于recharts - 重新绘制散点图工具提示以显示附加 Prop ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60600511/

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