Vue中使用ECharts

Vue中使用ECharts

1、安装ECharts

npm install echarts -S
#或者使用淘宝的镜像
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install echarts -S

2、项目引入

main.js
// 引入echarts
import echarts from 'echarts'
Vue.prototype.$echarts = echarts

3、打开项目文件

<div id="myChart" :style="{ '300px', height: '300px'}"></div>
	myEcharts(){
		// 基于准备好的dom,初始化echarts实例
		var myChart = this.$echarts.init(document.getElementById('myChart'));
		// 指定图表的配置项和数据
		var option = {
			title: {
				text: 'ECharts 入门示例'
			},
			tooltip: {},
			legend: {
				data:['销量']
			},
			xAxis: {
				data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
			},
			yAxis: {},
			series: [{
				name: '销量',
				type: 'bar',
				data: [5, 20, 36, 10, 10, 20]
			}]
		};
		// 使用刚指定的配置项和数据显示图表。
		myChart.setOption(option);
	}
	
	mounted() {
        this.myEcharts();
    }
原文地址:https://www.cnblogs.com/ljkltt/p/15244177.html