下载:
1.npm/yarn
npm install echarts --save
yarn add echarts --save
配置
- mian.js
// 引入echarts
import echarts from 'echarts'
//配置原型链上
Vue.prototype.$echarts = echarts
2.在局部引用
import * as echarts from 'echarts';
案例,用的是局部引用
html
<div id="aaa" style="width: 600px;height:400px;"></div>
js
import * as echarts from 'echarts';
data(){
return{
option:{
// 标题
title: {
text: '某站点用户访问来源',
subtext: '纯属虚构',
left: 'center'
},
// 光标悬浮提示
tooltip: {
trigger: 'item'
},
// 用于文字提示
legend: {
orient: 'vertical',
left: 'left',
},
// 数据体
series: [
{
name: '访问来源',//鼠标悬浮内容提示信息
type: 'pie',//表类型
radius: '50%',
data: [
{value: 1048, name: '搜索引擎'},
{value: 735, name: '直接访问'},
{value: 580, name: '邮件营销'},
{value: 484, name: '联盟广告'},
{value: 300, name: '视频广告'}
],
emphasis: {
// 各项样式
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
},
}
}
method
huahua() {
var chartDom = document.getElementById('aaa');
var myChart = echarts.init(chartDom);
myChart.setOption(this.option);
},
mounted
this.huahua();
即可