vue中使用echarts渲染不出来
<template>
<div id="app" class="login_area">
<div id="myChart" class="echarts"></div>
</div>
</template>
<script>
export default {
name: 'second',
data () {
return {
dataList:[],
time:[],
datas:[]
}
},
created: function () {
this.$axios.get("xxxx").then(res => {
this.dataList=res.data.result.group;
this.dataList.sort((a,b)=>{
return b.index - a.index
});
for(var value of this.dataList){
this.time.push(value.recharge_day)
this.datas.push(Number(value.mount))
}
});
},
mounted(){
this.drawLine();
},
methods: {
drawLine(){
let that=this;
console.log(that.time)
console.log(that.datas)
let myChart = this.$echarts.init(document.getElementById('myChart'));
myChart.setOption({
color: ['#90bcf3'],
tooltip: {
trigger: 'axis'
},
legend: {
data: ['收益/元'],
left: 20,
top: 20,
textStyle: {
color: ['#90bcf3']
}
},
toolbox: {
show: false,
feature: {
mark: {show: true},
dataView: {show: true, readOnly: false},
magicType: {show: true, type: ['line', 'bar', 'stack', 'tiled']},
restore: {show: true},
saveAsImage: {show: true}
}
},
calculable: true,
xAxis: [
{
type: 'category',
name: '日期',
boundaryGap: false,
data: that.time,
axisLine: {
lineStyle: {
color: ['#90bcf3']
}
},
axisLabel: {
textStyle: {
color: ['#000']
}
}
}
],
yAxis: [
{
type: 'value',
axisLine: {
lineStyle: {
color: ['#90bcf3']
}
},
axisLabel: {
textStyle: {
color: ['#000']
}
}
}
],
series: [
{
name: '收益/元',
type: 'line',
smooth: true,//平滑
stack: '总量',
data: that.datas
}
]
});
}
}
}
</script>
<style scoped>
.echarts{
width: 700px;
height: 300px;
}
</style>
打印数据:
页面:
求大佬指点哪里出问题了呢?
可能是mounted的时候没数据,console.log 改成
console.log(JSON.stringify(this.datas)
或者加断点再看输出。