1、npm安装Echarts
npm install echarts --save
运行程序报错卸载并降低Echarts版本
npm install echarts@4.8.0 --save
2、应用
<!-- 容器 -->
<div style="width:30%;height:10%" ref="chart"></div>
<script>
let Echarts = require("echarts/lib/echarts");
require("echarts/lib/chart/bar");//按需引入
export default{
data(){
return {
chart:null
}
},
mounted(){
this.initChart();
//自适应窗口大小
window.addEventListener("resize",()=>{
this.chart.resize();
})
},
methods:{
initChart(){
this.chart=Echarts.init(this.$refs.chart);
let option = {
title: {
text: 'ECharts 入门示例'
},
tooltip: {},
legend: {
data:['销量']
},
xAxis: {
data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
},
yAxis: {},
series: [{
name: '销量',
type: 'bar',
data: [5, 20, 36, 10, 10, 20]
}]
};
this.chart.setOption(option)
}
}
}
</script>