首页 > 解决方案 > 有没有办法在悬停时更改条形图中单元格的填充?- 图表

问题描述

我目前这样渲染图表:

<BarChart width={868} height={40} data={data}
                    margin={{top:0, bottom: 10, left:0, right:0}} barSize={5}>
            <Tooltip
              labelStyle={{ textAlign: 'left' }}
               cursor={{fill: "blue"}}
      position={{ x: this.state.mouseX - 20, y:-5 }}
            />
            <Bar dataKey="blocks"
                 onMouseOver={e => this.getMouseX(e)} >
              {
                data.map((entry, index) => {

                  const result = entry.result >  4  ?  TRASH : NO_TRASH;
                  return <Cell fill={result} key={index}/>;
                })
              }
            </Bar>
          </BarChart>

有没有办法在悬停栏时更改单元格/栏的颜色,而不是光标?

标签: javascriptreactjsd3.jsrecharts

解决方案


我使用了这个示例并将 onClick 更改为 onMouseOver 事件。工作正常。


推荐阅读