凉城孤影529 2023-04-12 20:23 采纳率: 50%
浏览 93
已结题

在vue中绘制echart图表无结果

创建echart图没显示内容

<template>
    <div id="123" style="width: 1000px;height: 600px;"></div>
</template>

<script>
import * as echarts from 'echarts'
import axios from 'axios'
export default{
    name:'BarGraph',
    data(){
        return{
            items:''
        }
    },
mounted () {
    var mychat = echarts.init(document.getElementById('123'));
    var url ='http://localhost:8081/vueData/details'
    var citys=[],confirm=[];
    axios.get(url).then(function(json){
        citys=json.data.city;
        confirm=json.data.confirm;
        console.log(citys);
        console.log(confirm);
    })
    mychat.setOption({
        legend: {
    top: '5%',
    left: 'center'
  },
        xAxis:{
            type:'category',
            data:citys
        },
        yAxis: {
              type: 'value'
            },
            
        series: [
    {
             type:'bar',
             data:confirm
        },
        ]
    })
}
}
</script>

运行结果就是这样,该怎么办啊

img

  • 写回答

2条回答 默认 最新

  • nssnail 2023-04-12 20:29
    关注

    setOption放在then里面就好

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 4月25日
  • 已采纳回答 4月17日
  • 创建了问题 4月12日