第一步
先下依赖 npm install echarts -S
第二步
项目引入echarts
如果在app和vue下面在引入必须加 * as 如果先引入echarts就不用加as 来引入 然后把echarts放到原型上就可以全局用了
第三步
实用
<template>
<div id="header">
<div id="div" ref="chart" style="width: 600px; height: 376px"></div>
</div>
</template>
<script>
export default {
mounted() {
this.getEchartData();
},
methods: {
getEchartData() {
let myChart = this.$echarts.init(this.$refs.chart);
let option = {
xAxis: {
type: "category",
data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
},
yAxis: {
type: "value",
},
series: [
{
data: [120, 200, 150, 80, 70, 110, 130],
type: "bar",
showBackground: true,
backgroundStyle: {
color: "rgba(180, 180, 180, 0.2)",
},
},
],
};
myChart.setOption(option);
},
},
};
</script>