官方文档:
<template>
<div class='con'>
<header>
</header>
<section>
<!--1-->
<div class="echart-box" id="main" ref="box"></div>
</section>
</div>
</template>
<script lang='ts' setup>
/** 接口 */
import { reactive, toRefs, ref, computed, onMounted } from 'vue';
import useCurrentInstance from '@/api/useCurrentInstance';
import * as echarts from 'echarts';
const { proxy } = useCurrentInstance()
/** prop */
/** 计算属性*/
//const xx = computed(() => [])
/** data */
const state = reactive({
tableData: []
})
const { tableData} = toRefs(state);
//2
const box=ref();
/** 监听 */
/** 生命周期 */
onMounted(() => {
//3
showEcarts();
})
//4
const showEcarts=()=> {
// 基于准备好的dom,初始化echarts实例 两种写法
var userdom = box.value;
var myChart = echarts.init(userdom);
//var myChart = echarts.init(document.getElementById('main'));
var option = {
title: {
text: "ECharts",
},
xAxis: {
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {},
legend: {
data: ["牛波","撒波"],
},
series: [
{
name: "牛波",
type: 'bar',
data: [23, 24, 18, 25, 27, 28, 25],
},
{
name: "撒波",
type: 'bar',
data: [20, 24, 18, 25, 27, 28, 25],
}
]
};
myChart.setOption(option);
}
/** 接口 */
</script>
<style>
/**5 */
.echart-box{
width: 500px;
height: 350px;
border: 3px solid pink;
margin: 20px auto;
}
</style>