2

在下面的图片/代码中,应该只出现一次 hi、hello 和 bye。关于为什么重复的任何想法?

在浏览器中编辑:http: //jsfiddle.net/ndLhnegs/318/编辑:我在这里做了另一个更简单的例子:http: //jsfiddle.net/7coegorj/2/

在此处输入图像描述

React Rechart 组件:

const {Scatter, ScatterChart, XAxis, YAxis, CartesianGrid, Tooltip, Legend} = Recharts;
const Chart = React.createClass({
  render(){
      const selected = [
        {value:'obj1',label:'Obj1'},
        {value:'obj2',label:'Obj2'},
        {value:'obj3',label:'Obj3'},
        {value:'obj4',label:'Obj4'},
      ]
      const scatters = selected.map((s) => {
        let data = [
          {x:'hi',y:Math.random() * 10},
          {x:'hello',y:Math.random() * 10},
          {x:'bye',y:Math.random() * 10},
        ]
        return (
          <Scatter
            key={s.label}
            name={s.label}
            data={data}
            fill='#000'
            line
            shape="cross" />
        );
      });
      return (
        <ScatterChart width={600} height={400} margin={{ top: 20, right: 20, bottom: 20, left: 20 }}>
          <XAxis  dataKey='x' name='Macro' />
          <YAxis type="number" dataKey={'y'} name='Grams' unit='g' />
          <CartesianGrid />
          <Tooltip cursor={{ strokeDasharray: '3 3' }} />
          <Legend />
          {scatters}
        </ScatterChart >
      );
    }
})

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

在这里提交了一个 GitHub 问题 - https://github.com/recharts/recharts/issues/1034

4

1 回答 1

2

要解决此问题,我相信您可以使用allowDuplicatedCategories={false}此处文档中的内容:http ://recharts.org/en-US/api/XAxis#allowDuplicatedCategory

于 2019-04-15T18:41:29.100 回答