1.安装
$ npm install echarts vue-echarts
2.在main.js中引用
import Vue from 'vue'
import ECharts from 'vue-echarts'
// 引入折线图等组件
import 'echarts/lib/chart/line'
import 'echarts/lib/chart/bar'
// 引入饼图
import 'echarts/lib/chart/pie'
// 引入提示框和title组件,图例
import 'echarts/lib/component/tooltip'
import 'echarts/lib/component/title'
import 'echarts/lib/component/legend'
Vue.component('v-chart', ECharts)
3.打开 build 文件夹中的 webpack.base.conf.js 文件,修改
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src'), resolve('test'), resolve('node_modules/vue-echarts-v3/src')]
}
4.使用
<style>
.echarts {
width: 100%;
height: 100%;
}
</style>
<template>
<v-chart :options="polar"/>
</template>
<script>
import ECharts from 'vue-echarts/components/ECharts'
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>
5.下载主题及引入
在echarts官网下载主题https://echarts.baidu.com/theme-builder/

image.png
<template>
<v-chart theme="ovilia-green" :options="polar"/>
</template>
<script>
import theme from '../theme.json'
ECharts.registerTheme('ovilia-green', theme); //引入主题
</script>
效果图如下

image.png