echarts中国JSONajax

.ajax()请求json数据,并处理,注入echart表格

2016-11-07  本文已影响119人  6659a0f02826
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>echartDemo1</title>
</head>
<body>
    <div id="main" style="width: 600px;height:400px;"></div>

    <script src="jquery-3.1.1.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="echarts.min.js"></script>
    <script type="text/javascript">
        var url = '这里输入请求的网址链接';
        var year = [],temp = [];
        console.log("aa");
        $.ajax({
            type: 'get',
            url:url,
            dataType:'json',
            success:function(data){
                for(var o in data['data']) {
                    year.push(data['data'][o]['date'].slice(0,4)-0);
                    temp.push(data['data'][o]['value']);
                }
                console.log(temp);
                console.log(year);
                var myChart = echarts.init(document.getElementById('main'));
                        option = {
                        title: {
                                text: '统计'
                        },
                        tooltip: {
                                trigger: 'axis'
                        },
                        legend: {
                                data:['统计']
                        },
                        grid: {
                                left: '3%',
                                right: '4%',
                                bottom: '3%',
                                containLabel: true
                        },
                        toolbox: {
                                feature: {
                                        saveAsImage: {}
                                }
                        },
                        xAxis: {
                                type: 'category',
                                boundaryGap: false,
                                data: year
                        },
                        yAxis: {
                                type: 'value'
                        },
                        series: [
                        {
                                name:'统计',
                                type:'line',
                                stack: '总量',
                                data:temp
                        }

                ]
                };
                myChart.setOption(option);
            }
    })
    </script>
    </body>
</html>


上一篇下一篇

猜你喜欢

热点阅读