安装echarts依赖
npm install echarts -S
创建图表
全局引入
main.js
// 引入echarts import echarts from 'echarts'
Vue.prototype.$echarts = echarts
这里也可以在router下index.js引入,看规定
HTML代码:
HTML代码:
<div id="myChart" :style="{width: '300px', height: '300px'}"></div>
export default {
name: 'hello',
data () {
return {
msg: 'Welcome to Your Vue.js App'
}
},
mounted:function(){
this.creatE();
},
methods: {
creatE:function(){
let myChart = this.$echarts.init(document.getElementById('myChart'))
// 绘制图表
myChart.setOption({
title: { text: '在Vue中使用echarts' },
tooltip: {},
xAxis: {
data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
},
yAxis: {},
series: [{
name: '销量',
type: 'bar',
data: [5, 20, 36, 10, 10, 20]
}]
});
}
}
}
需要在显示图像的页面,也就是写creatE方法的页面加上下面图片上的东西
非全局引用:
// 引入基本模板let echarts = require('echarts/lib/echarts')// 引入柱状图组件require('echarts/lib/chart/bar')// 引入提示框和title组件require('echarts/lib/component/tooltip')require('echarts/lib/component/title')
以上写在export default {}上面与import xxx from xxx平齐
QQ群:553997290
公众号: