Vue3使用Echarts导致tooltip失效问题及解决方法
更新时间:2023年08月31日 11:14:00 作者:MichstaBe Stars
Vue3 使用 proxy 对象代理,而 echarts 则使用了大量的全等(===), 对比失败从而导致了bug,这篇文章主要介绍了Vue3使用Echarts导致tooltip失效问题及解决方法,需要的朋友可以参考下
版本 vue3.2.47 echarts5.4.1
使用响应式对象存储 echarts 实例,导致 tooltip 功能失效;
原因:Vue3 使用 proxy 对象代理,而 echarts 则使用了大量的全等(===), 对比失败从而导致了bug。
解决方法:将ref或reactive对象换成普通变量来保存 echarts 实例。
初始化图表
// 初始化柱状图
function initBarChart(data) {
const myChart = echarts.init(unref(barRef));
const option: EChartsOption = {
color: ['#3398DB'],
tooltip: {
trigger: 'axis',
axisPointer: { type: 'shadow' }
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: [
{
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
axisTick: { alignWithLabel: true }
}
],
yAxis: [{ type: 'value' }],
series: [
{
name: '直接访问',
type: 'bar',
data: [10, 52, 200, 334, 390, 330, 220]
}
]
};
myChart.setOption(option);
}更新图表数据
// 更新柱状图
function updateBarChart(data) {
const getLineChartInstance = echarts.getInstanceByDom(unref(barRef)!);
getLineChartInstance && getLineChartInstance.setOption({ series: [{ data }] });
}到此这篇关于Vue3使用Echarts导致tooltip失效的文章就介绍到这了,更多相关Vue3使用Echarts tooltip失效内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
关于el-table-column的formatter的使用及说明
这篇文章主要介绍了关于el-table-column的formatter的使用及说明,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2022-10-10
基于vue3+antDesign2+echarts 实现雷达图效果
这篇文章主要介绍了基于vue3+antDesign2+echarts 实现雷达图,本文通过实例代码图文相结合给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2022-08-08


最新评论