当rechart中值为0时如何隐藏散点图

2023-11-30

我正在使用 rechart ,因为我有一个问题。我正在使用散点图。如果散点图的值为 0 散点显示在 x 轴顶部(Y 值为 0),我不想在值为“0”时显示散点

我该怎么办,请有人帮忙。

Code:

  const {ScatterChart, Scatter, XAxis, YAxis, ZAxis, CartesianGrid, Tooltip, Legend} = Recharts;
const data01 = [{x: 100, y: 200}, {x: 120, y: 0},
                ];


const ThreeDimScatterChart = React.createClass({
    render () {
    return (
        <ScatterChart width={400} height={400} margin={{top: 20, right: 20, bottom: 20, left: 20}}>
        <XAxis type="number" dataKey={'x'} name='stature' unit='cm'/>
        <YAxis type="number" dataKey={'y'} name='weight' unit='kg'/>
     
        <CartesianGrid />
        <Tooltip cursor={{strokeDasharray: '3 3'}}/>
        <Legend />
        <Scatter name='A school' data={data01} fill='#8884d8' shape="star"/>

      </ScatterChart>
    );
  }
})

ReactDOM.render(
  <ThreeDimScatterChart />,
  document.getElementById('container')
);

Output:

enter image description here

因此,在该图像中,第二个散点的 x 值为 120,y 值为 0,因此如果 y 值为 0 。我根本不想显示分散。

请在这方面帮助我

Thanks


由于您完全定义了数据,因此您只需替换0 with null there.

const data01 = [{x: 100, y: 200}, {x: 120, y: null}];

在现实世界中,您从其他地方获取源数据,必须对源数据进行转换,以便0点是null反而。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

当rechart中值为0时如何隐藏散点图 的相关文章

随机推荐