xiongmao34
2019-11-21 09:41
采纳率: 60%
浏览 1.1k
已采纳

ajax的值怎样传递到echarts中 series的data中

$(function(){
                var xlm = {
                    arr : [],
                    init : function(){
                        //ajax 调用
                        $.ajax({
                            type:"GET", 
                            url:'1.json',
                            dataType:"json",
                            success:function(datas){ 
                                $.each(datas.data,function(i,n){
                                    console.log(datas.data[i].title)
                                })
                            }
                        });
                    }
                };
                xlm.init();
                //图形
                var dom = document.getElementById("container");
                var myChart = echarts.init(dom);
                var app = {};
                option = null;
                option = {
                    title: {
                        text: '某站点用户访问来源',
                        subtext: '纯属虚构',
                        x: 'center'
                    },
                    tooltip: {
                        trigger: 'item',
                        formatter: "{a} <br/>{b} : {c} ({d}%)"
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                        data: []
                    },
                    series: [{
                        name: '访问来源',
                        type: 'pie',
                        radius: '55%',
                        center: ['50%', '60%'],
                        data: [],
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }]
                };
                if(option && typeof option === "object") {
                    myChart.setOption(option, true);
                }
                })

1.json值

{
    "code": 0,
    "msg": "OK",
    "data": [
        {
            "title": "a",
            "value": "72"            
        },
        {
            "title": "b",
            "value": "11"            
        },
        {
            "title": "c",
            "value": "1"            
        },
        {
            "title": "d",
            "value": "4"            
        },
        {
            "title": "e",
            "value": "6"            
        },
        {
            "title": "f",
            "value": "0"            
        },
        {
            "title": "g",
            "value": "3"            
        },
        {
            "title": "h",
            "value": "3"            
        }
    ]
}

3条回答 默认 最新

相关推荐 更多相似问题