一:npm安装
npm install echarts --save
cnpm install echarts --save
二:在main.js中引入
import * as echarts from 'echarts'
Vue.use(echarts);
三:vue文件中使用
<div id="myChart" style="width: 100%;height: 600px"></div>
export default {
data () {
return {}
},
mounted(){
this.drawLine();
},
methods: {
drawLine(){
let xDataArr = [];
let yDataArr = [];
let echarts = require('echarts');
let mCharts = echarts.init(document.getElementById('myChart'));
myChart.setOption({
title: {
text: '统计数据'
},
xAxis: {
type: 'category',
data: xDataArr ,
},
yAxis: {
type: 'value',
},
series: [{
name: '销量',
type: 'bar',
data: yDataArr
}]
});
mCharts.setOption(option)
}
}
}
|