import * as eCharts from 'echarts' import type { EChartsOption } from 'echarts' type themeType = 'light' | 'dark' interface optsType { renderer: 'svg' | 'canvas' } /** * 初始化 echart 图表 * @param dom dom元素 * @param options 图表配置 * @param theme 图表主题 'light' | 'dark' * @param opts 图表渲染模式 'svg' | 'canvas' */ export function useECharts( dom: HTMLElement, options: EChartsOption, theme: themeType = 'light', opts: optsType = { renderer: 'svg' } ) { // 初始化并传入配置 const chart = eCharts.init(dom, theme, opts) chart.setOption(options) // 返回实例对象 return chart }