帮我用vue3写一个echarts的样例
以下是一个使用Vue3和Echarts的示例代码:
<template>
<div>
<div ref="chart" style="height: 400px;"></div>
</div>
</template>
<script>
import {ref, onMounted} from 'vue';
import * as echarts from 'echarts';
export default {
setup() {
const chart = ref(null);
onMounted(() => {
const myChart = echarts.init(chart.value);
const option = {
title: {
text: 'Echarts demo'
},
tooltip: {},
legend: {
data:['销量']
},
xAxis: {
data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
},
yAxis: {},
series: [{
name: '销量',
type: 'bar',
data: [5, 20, 36, 10, 10, 20]
}]
};
myChart.setOption(option);
});
return { chart };
}
}
</script>
该示例创建了一个简单的柱状图,并在Vue3中使用Echarts进行了渲染。在setup函数中,我们使用ref来创建一个指向chart DOM元素的引用,并在onMounted钩子函数中,初始化Echarts图表并设置选项。最后,我们将chart引用返回以便在模板中使用。
原文地址: https://www.cveoy.top/t/topic/bhto 著作权归作者所有。请勿转载和采集!