<!-- 商家销售统计的横向柱状图-->
<template>
<div class="com-container">
<div class="com-chart" ref="seller_ref">
</div>
</div>
</template>
<script>
export default {
data(){
return{
chartInstance:null,
allData:null
}
},
mounted(){
this.initChart()
},
methods:{
//初始化echartInstance对象
initChart(){
this.chartInstance=this.$echarts.init(this.$refs.seller_ref)
},
//获取服务器的数据
async getData(){
const { data:ret }=await this.$http.get('seller')
this.allData=ret
this.updataChart()
},
//更新图表
updataChart(){
const sellerNames=this.allData.map((item)=>
item.name
)
const sellerValues=this.allData.map((item)=>
item.value
)
const option={
xAxis:{
type:'value'
},
yAxis:{
type:'category',
data:sellerNames
},
series:[
{
type:'bar',
data:sellerValues
}
]
}
this.chartInstance.setOption(option)
}
}
}
</script>
<style>
</style>
自己写入数据也显示不出来视图
如何解决
应该是echarts加载错误,按F12看看报什么错误。
获取数据的方法没有调用,mounted的时候要调用吧
baseUrl加上http://
http://192.168.0.103:8888/api
div要设置高度
getDate这个方法没调用