Vue使用 echarts

  1. 安装
npm install echarts --save

  1. 引入

​main.js​

import echarts from 'echarts';
Vue.prototype.$echarts = echarts;

  1. 使用

注意: 必须制定宽度和高度,宽度可以是继承父元素

<template>
<div id="main">
<div ref="myEcharts" style="width:500px;height: 300px;">
</div>
</div>
</template>

<script>
export default {
mounted(){
this.init();
},
methods: {
init() {
let myChart = this.$echarts.init(this.$refs.myEcharts));
// 绘制图表
let option;
option = {
title: {
text: 'ECharts 入门示例'
},
tooltip: {},
legend: {
data:['销量']
},
xAxis: {
data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
},
yAxis: {},
series: [{
name: '销量',
type: 'bar',
data: [5, 20, 36, 10, 10, 20]
}]
};

// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
}
}
}
</script>

  1. 效果
    Vue echarts 入门_echarts