vue-echarts和echarts的區別:html
v4.0.1
+ 開發,依賴 Vue.js v2.2.6
+,功能同樣的只是把它封裝成vue插件 這樣更方便以vue的方式去使用它。vue-echarts特徵:vue
git地址:https://github.com/ecomfe/vue-echartsnode
$ npm install vue-echarts
$ bower install vue-echarts
直接下載 dist/vue-echarts.js
並在 HTML 文件中引入:webpack
<script src="path/to/vue-echarts/dist/vue-echarts.js"></script>
import Vue from 'vue' import ECharts from 'vue-echarts/components/ECharts.vue'
// 手動引入 ECharts 各模塊來減少打包體積 import 'echarts/lib/chart/bar' import 'echarts/lib/component/tooltip' import 'echarts/lib/component/polar' import 'echarts/lib/component/legend' import 'echarts/lib/component/title.js'
// 註冊組件後便可使用 Vue.component('v-chart', ECharts)
用 vue-cli 搭建的項目,打開 build 文件夾中的 webpack.base.conf.js 文件git
一、webpack 1.x 修改爲以下github
{ test: /\.js$/, loader: 'babel', include: [ path.join(prjRoot, 'src'), path.join(prjRoot, 'node_modules/vue-echarts-v3/src') ], exclude: /node_modules(?![\\/]vue-echarts-v3[\\/]src[\\/])/ },
二、webpack 2.x 修改爲以下web
{ test: /\.js$/, loader: 'babel-loader', include: [resolve('src'), resolve('test'), resolve('node_modules/vue-echarts-v3/src')] }
<style> .echarts { width: 100%; height: 100%; } </style> <template> <v-chart theme="ovilia-green" :options="polar"/> </template> <script> import ECharts from 'vue-echarts/components/ECharts' import theme from '../theme.json' ECharts.registerTheme('ovilia-green', theme); //引入主題 export default { components: { 'v-chart': ECharts }, data () { return { polar: { title : { text: '會員數據統計', subtext: '動態數據', x:'center' }, tooltip : { trigger: 'item', formatter: "{a} <br/>{b} : {c} ({d}%)" }, legend: { show: true, orient: 'vertical', left: 'left', data: ['微信訪問','公衆號訪問','掃碼進入','分享進入','搜索訪問'] }, series : [ { name: '訪問來源', type: 'pie', radius : '55%', center: ['50%', '60%'], data:[ {value:335, name:'微信訪問'}, {value:310, name:'公衆號訪問'}, {value:234, name:'掃碼進入'}, {value:135, name:'分享進入'}, {value:1548, name:'搜索訪問'} ], itemStyle: { emphasis: { shadowBlur: 10, shadowOffsetX: 0, shadowColor: 'rgba(0, 0, 0, 0.5)' } } } ] } } } } </script>
自定義主題vue-cli
只要把定義主題樣式theme.json文件經過下面方法引入便可
shell
import theme from '../theme.json' ECharts.registerTheme('ovilia-green', theme);
圖示:npm
更多詳細信息請參考 ECharts 的 API 文檔。