一、安裝echarts:
cnpm i echarts -D

二、在vue-cli的main.js文件中引用echarts:
import charts from 'echarts'
Vue.prototype.$echarts = charts

三、echarts詳細代碼:
echarts.vue:
<template>
<div>
<div id="myChart">
</div>
</div>
</template>
<script>
export default {
methods: {
drawLine(){
// 基於准備好的dom,初始化echarts實例
let myChart = this.$echarts.init(document.getElementById('myChart'));
this.$axios.get("http://127.0.0.1:8000/get_data")
.then(function(res){
// 繪制圖表
myChart.setOption({
title: { text: res.data.title },
tooltip: {},
xAxis: {
data: res.data.xAxisData
},
yAxis: {},
series: [{
name: '銷量',
type: 'bar',
data: res.data.seriesData
}]
});
})
.catch(function(err){
console.log(err);
})
}
},
mounted(){
this.drawLine();
}
}
</script>
<style>
#myChart{
height: 500px;
}
</style>

四、上面的圖表數據通過axios獲取,node.js代碼如下:
let express = require("express");
let app = express();
app.get("/get_data", function(req, res, next){
res.header("Access-Control-Allow-Origin", "*");
let response = {
title: '在Vue中使用echarts',
xAxisData: ["襯衫","羊毛衫","雪紡衫","褲子","高跟鞋","襪子"],
seriesData: [10, 26, 16, 20, 16, 30]
};
res.type('application/json');
res.jsonp(response);
});
app.listen(8000, function(){
console.log("開始執行請求");
});
