<ReactEcharts onChartReady={this.onChartReady}/>
onChartReady(echart) {
echart.getZr().on('click',params=>{
const pointInPixel = [params.offsetX, params.offsetY];
if (echart.containPixel('grid',pointInPixel)) {
let xIndex = echart.convertFromPixel({seriesIndex:0},[params.offsetX, params.offsetY])[0];
/*事件处理代码书写位置*/
let score = this.props.xData[xIndex];
this.props.showYear(score);
}
});
}
本文介绍如何在React中使用ECharts并实现点击事件处理。通过获取图表元素坐标,判断点击位置是否在有效区域内,并根据点击位置获取对应数据索引及值,进而触发相关业务逻辑。适用于需要对图表进行交互操作的场景。
1289

被折叠的 条评论
为什么被折叠?



