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失效內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
關于el-table-column的formatter的使用及說明
這篇文章主要介紹了關于el-table-column的formatter的使用及說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-10-10
基于vue3+antDesign2+echarts?實現(xiàn)雷達圖效果
這篇文章主要介紹了基于vue3+antDesign2+echarts?實現(xiàn)雷達圖,本文通過實例代碼圖文相結合給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-08-08

