Echarts 官網:http://echarts.apache.org/zh/index.html
安裝依賴
npm安裝
npm install echarts -S
或者用淘寶鏡像安裝
npm install -g cnpm --registry=https://registry.npm.taobao.org cnpm install echarts -S
全局引入
在main.js中引入
import * as echarts from 'echarts';
Vue.prototype.$echarts = echarts
注意:一定要注意引入引入方式,否則會報錯
若有報錯可參照vue中使用echarts報錯:“TypeError: Cannot read property ‘init‘ of undefined“報錯原因及解決方案進行解決
創建圖表
此例是創建柱狀圖
<template> <div> <div id="main" style="width: 600px;height:400px;"></div> </div> </template> <script> export default { name: 'index', data() { return { }; }, mounted() { this.myecharts() }, methods: { myecharts(){ var myChart = this.$echarts.init(document.getElementById('main')); // 指定圖表的配置項和數據 var option = { title: { text: 'ECharts 入門示例' }, tooltip: {}, legend: { data:['銷量'] }, xAxis: { data: ["襯衫","羊毛衫","雪紡衫","褲子","高跟鞋","襪子"] }, yAxis: {}, series: [{ name: '銷量', type: 'bar', data: [5, 20, 36, 10, 10, 20] }] }; // 使用剛指定的配置項和數據顯示圖表。 myChart.setOption(option); } }, }; </script>

