1- 安裝 echarts 依賴
npm install echarts -S
2- 創(chuàng)建圖表全局引入
(1),在main.js 中引入
?import echarts from 'echarts'
(2),在main.js 中加代碼
Vue.prototype.$echarts = echarts

3-頁面里面調(diào)用使用
1,引入echarts
import echarts from 'echarts'

三步走:
1,給指點的圖表設(shè)置寬高屬性
2,設(shè)置標簽的id名,進行初始化圖表
3,開始繪制圖表,生成你想要的圖表
<div id="myChart" :style="{width: '300px', height: '300px'}"></div>
(這里的id名必須命名)
export default {
? name: 'hello',
? data () {
? ? return {
? ? }
? },
? mounted(){
? ? this.drawLine();
? },
? methods: {
? ? drawLine(){
? ? ? ? // 基于準備好的dom,初始化echarts實例
? ? ? ? let myChart = this.$echarts.init(document.getElementById('myChart'))
? ? ? ? // 繪制圖表
? ? ? ? myChart.setOption({
? ? ? ? ? ? title: { text: '在Vue中使用echarts' },
? ? ? ? ? ? tooltip: {},
? ? ? ? ? ? xAxis: {
? ? ? ? ? ? ? ? data: ["襯衫","羊毛衫","雪紡衫","褲子","高跟鞋","襪子"]
? ? ? ? ? ? },
? ? ? ? ? ? yAxis: {},
? ? ? ? ? ? series: [{
? ? ? ? ? ? ? ? name: '銷量',
? ? ? ? ? ? ? ? type: 'bar',
? ? ? ? ? ? ? ? data: [5, 20, 36, 10, 10, 20]
? ? ? ? ? ? }]
? ? ? ? });
? ? }
? }
}
注意:我們要在mounted生命周期函數(shù)中實例化echarts對象。因為我們要確保dom元素已經(jīng)掛載到頁面中
