官网地址:https://echarts.apache.org/zh/index.html
下载:
npm install echarts --save
引用:
import echarts from 'echarts'
Vue.prototype.$echarts = echarts
使用:
该处直接参考官网写的:https://echarts.apache.org/zh/tutorial.html#5%20%E5%88%86%E9%92%9F%E4%B8%8A%E6%89%8B%20ECharts
<template>
<div id="home">
<div id="main" style="width: 600px;height:400px;"></div>
</div>
</template>
<script>
export default {
name: 'Home',
mounted () {
this.init()
},
methods:{
init(){
var myChart = this.$echarts.init(document.getElementById('main'));
// 指定图表的配置项和数据
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);
}
}
}
</script>
注意事项:
如果你下载下来的是5.0版本运行时可能有错。(本人之前5.0.2,现在4.9.0)
如果你出现运行不了,请参考这篇文章:https://www.cnblogs.com/cyhsmile/p/14098269.html
解决方法:
npm uninstall echarts //卸载
npm install echarts@4.9.0//重装
npm fund
npm run dev
然后就好了,本人亲测有效。