在Vue项目中使用ECharts
cnpm i echarts --save
import echarts from 'echarts'
Vue.prototype.$echarts = echarts
<template>
<div>
<h3>ECharts</h3>
<div ref="chart" style="width:600px;height:300px;"></div>
</div>
</template>
<script>
export default {
data () {
return {
}
},
mounted() {
this.init();
},
methods: {
init() {
var chart = this.$refs.chart;
const myChart = this.$echarts.init(chart);
var option = {
title: {
text: 'Echarts Demo'
},
tooltip: {},
xAxis: {
data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
},
yAxis: {},
series: [{
name: '销量',
type: 'bar',
data: [5, 20, 36, 10, 10, 20]
}]
};
myChart.setOption(option);
}
}
}
</script>