VUE+echarts的基础使用
发现echarts中没有vue的初始化起步教程,摸索了一下
官方文档 链接
- 安装
echarts
,通过 npm 获取 echarts
npm install echarts --save
- 新建组件,这里遵循vue中的ref的使用
<template>
<div class="Specification">
<div ref="main" style="width: 600px;height:400px;"></div>
</div>
</template>
- 初始化使用
export default {
name: 'Specification',
data(){
return{
option:{
// 指定图表的配置项和数据
title: {
text: 'ECharts 入门示例'
},
tooltip: {},
legend: {
data: ['销量']
},
xAxis: {
data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
},
yAxis: {},
series: [{
name: '销量',
type: 'bar',
data: [5, 20, 36, 10, 10, 20]
}]
}
}
},
mounted() {
// 基于准备好的dom,初始化echarts实例
let myChart = this.$echarts.init(this.$refs.main);
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(this.option);
}
}