1. 首先先安装echarts
npm install echarts
2. main.js引入 把 import echarts from 'echarts' 改成如下即可
import * as echarts from 'echarts'
Vue.prototype.$echarts = echarts
3. 调用
<div class="echart" ref="echartId"></div>
var myChart = this.$echarts.init(this.$refs.echartId)
// 绘制图表
myChart.setOption({
title: { text: "在Vue中使用echarts" },
tooltip: {},
xAxis: {
data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
},
yAxis: {},
series: [
{
name: "销量",
type: "bar",
data: [5, 20, 36, 10, 10, 20]
}
]
});
4. css设置
.echart{
width:300px;
height:300px;
}