vue 引入 echarts 图表

1:npm install echarts --save
2:在main.js写:
import echarts from 'echarts/lib/echarts'

// 引入提示框组件、标题组件、工具箱组件。
import 'echarts/lib/component/tooltip'
import 'echarts/lib/component/title'
import 'echarts/lib/component/toolbox'
Vue.prototype.$echarts = echarts

3:在需要的组件引入需要的模块图片
如在home里:

1)html、
<div id="pie" ref="pie_wrap"></div>
import 'echarts/lib/chart/pie'
mounted () {
// 初始化echarts实例
let myChart = this.$echarts.init(this.$refs.pie_wrap)
// 绘制图表
myChart.setOption(
{
color: ['rgb(102,208,113)', 'rgb(223,223,223)'],
series: [
{
name: '访问来源',
type: 'pie',
radius: ['95%', '100%'],
avoidLabelOverlap: false,
label: {
normal: {
show: true,
position: 'center',
textStyle: {
fontSize: '48',
fontWeight: 'bold'
}
},
emphasis: {
show: true,
textStyle: {
fontSize: '30',
fontWeight: 'bold'
}
}
},
labelLine: {
normal: {
show: false
}
},
data: [
{value: 30, name: ''},
{value: 70, name: ''}
],
silent: true
}
]
}
)
}

2)
// 引入柱状图
import 'echarts/lib/chart/bar'
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main')); // 绘制图表 myChart.setOption({ title: { text: 'ECharts 入门示例' }, tooltip: {}, xAxis: { data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子'] }, yAxis: {}, series: [{ name: '销量', type: 'bar', data: [5, 20, 36, 10, 10, 20] }] });
 

猜你喜欢

转载自www.cnblogs.com/luckyShuang/p/11242193.html