This commit is contained in:
duanliang
2025-04-23 02:00:16 +08:00
parent 5ce6f4c899
commit cc43098ca7
12 changed files with 114 additions and 33 deletions

View File

@@ -4,14 +4,22 @@ import { guid } from '@/utils/util'
export function useEchart() {
let chart = null
let chartVal = ref(null)
let id = ref(guid())
const initChart = () => {
const dom = document.getElementById(id.value)
chart = echarts.init(dom)
chartVal.value = chart
}
const setOption = (params, update = false) => {
chart.setOption(params, update)
}
const clearOption = () => {
// 将series设置为空数组可以清空图表内容
chart.setOption({
series:[]
})
}
const dispose = () => {
chart.dispose()
chart = null
@@ -25,5 +33,5 @@ export function useEchart() {
window.addEventListener('resize', resize)
})
return { id, chart, setOption, dispose, initChart }
return { id, chart, setOption, dispose, initChart,chartVal,clearOption }
}