1、下载插件
npm i install echarts --save
2、全局注册组件
在 main.js 中
import echarts from "echarts";
Vue.prototype.$echarts = echarts;
3、在文件中使用
<template>
<div id="app">
<div id="main"></div>
</div>
</template>
<script>
export default {
name: "app",
methods: {
drawChart() {
// 基于准备好的dom,初始化echarts实例
let myChart = this.$echarts.init(document.getElementById("main"));
// 指定图表的配置项和数据
let option = {
title: {
text: "数据报表"
},
tooltip: {},
legend: {
data: ["销量"]
},
xAxis: {
data: ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"]
},
yAxis: {},
series: [
{
name: "营业额",
type: "bar",
data: [5, 20, 36, 10, 10, 20, 19]
}
]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
}
},
mounted() {
this.drawChart();
}
};
</script>
<style scoped="scoped">
</style>