欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 创投人物 > 移动端(手机)ECharts 的myChart.on(‘click‘,还生效吗我怎么触发不了,没得鼠标触发不了点击事件

移动端(手机)ECharts 的myChart.on(‘click‘,还生效吗我怎么触发不了,没得鼠标触发不了点击事件

2025/5/15 15:04:01 来源:https://blog.csdn.net/2302_76925238/article/details/147925780  浏览:    关键词:移动端(手机)ECharts 的myChart.on(‘click‘,还生效吗我怎么触发不了,没得鼠标触发不了点击事件

移动端可以DOM事件替代 myChart.getDom().addEventListener('mousedown', function (event) {

写在setOption(option)后面这样手机也能触发pc端一样的饼图效果

    await  myChart.setOption(option);myChart.getDom().addEventListener('mousedown', function (event) {const params = event.target;if (params) {let fillColor = params.getAttribute('fill');  // 获取 fill 属性if (fillColor && fillColor.startsWith('rgb')) {const result = fillColor.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/i);if (result) {const r = parseInt(result[1]).toString(16).padStart(2, '0');const g = parseInt(result[2]).toString(16).padStart(2, '0');const b = parseInt(result[3]).toString(16).padStart(2, '0');fillColor = `#${r}${g}${b}`.toUpperCase();}} else {fillColor = fillColor?.toUpperCase();}const dataIndex = chartData.findIndex((item) => item.color == fillColor);if (dataIndex !== -1) {// 清除之前高亮的状态myChart.dispatchAction({type: 'downplay', // 清除之前高亮的状态seriesIndex: 0,dataIndex: null, // 取消所有高亮});// 高亮当前选中的区域myChart.dispatchAction({type: 'highlight',seriesIndex: 0,dataIndex: dataIndex,});// 显示提示框myChart.dispatchAction({type: 'showTip',seriesIndex: 0,dataIndex: dataIndex,});}}
});

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词