1.安裝
npm install echarts --save
2.引入
全局引入(main.js)
import echarts from 'echarts' Vue.prototype.$echarts=echarts
//如果報錯可以使用
import *as echarts from 'echarts'
局部引用(頁面script)
import echarts from 'echarts'
3. 創建容器(直接在template里面寫上 div容器)
<div id="myChart"></div>
4.配置表格數據(data中)
option = { title: { text: 'Referer of a Website', subtext: 'Fake Data', left: 'center' }, tooltip: { trigger: 'item' }, legend: { orient: 'vertical', left: 'left' }, series: [ { name: 'Access From', type: 'pie', radius: '50%', data: [ { value: 1048, name: 'Search Engine' }, { value: 735, name: 'Direct' }, { value: 580, name: 'Email' }, { value: 484, name: 'Union Ads' }, { value: 300, name: 'Video Ads' } ], emphasis: { itemStyle: { shadowBlur: 10, shadowOffsetX: 0, shadowColor: 'rgba(0, 0, 0, 0.5)' } } } ] };
在官網復制修改數據即可
5.繪制圖表(methods)
rawLine(){
let myChart = this.$echarts.init(document.getElementById("myChart")); myChart.setOption(this.option);
}
6.展示圖表
需要講“繪制圖表代碼的函數,掛載到mounted”
mounted() { this.drawLine(); },