highcharts用ajax获取json数据的入门案例

我的软件测试资源小站:www.qabujiaban.com

 

<!DOCTYPE html>  
<html lang="en">  
    <head>  
        <title>http://blog.csdn.net/ime33 AJAX异步请求数据</title>  
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="this is my page">
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <script type="text/javascript" src="../WebRoot/WEB-INF/js/jquery-3.3.1.min.js"></script>
        <script type="text/javascript" src="../WebRoot/WEB-INF/js/highcharts.js"></script>  
        <script type="text/javascript" src="../WebRoot/WEB-INF/js/exporting.js"></script>  
        <script type="text/javascript" src="../WebRoot/WEB-INF/js/dark-unica.js"></script>  
        <script type="text/javascript">  
            $(function () {  
        // 异步加载数据第二种方式  
                var options={  
                    chart:{  
                        renderTo:'container',  
                        type:'line'//line column  
                    },  
                    title:{  
                        text:'异步获取数据'  
                    },  
                    subtitle: {  
                        text: '折线图',  
                        x: -20  
                    },  
                    xAxis: {  
                        categories: ['1月', '2月', '3月', '4月', '5月', '6月',  
                                     '7月', '8月', '9月', '10月', '11月', '12月']  
                    },  
                    yAxis: {  
                        title: {  
                            text: '金额 (元)'  
                        },  
                        plotLines: [{  
                            value: 0,  
                            width: 1,  
                            color: '#808080'  
                        }]  
                    },  
                    tooltip: {  
                        valueSuffix: '万'  
                    },  
                    legend: {  
                        layout: 'vertical',  
                        align: 'right',  
                        verticalAlign: 'middle',  
                        borderWidth: 0  
                    },  
                    Loading:{  
                        hideDuration: 1000,//淡出效果的持续时间(以毫秒为单位)  
                        showDuration: 1000,//淡入效果的持续时间(以毫秒为单位)  
                        labelStyle: {//加载标签的span的CSS样式  
                            fontStyle: 'italic',  
                            color:'red',  
                            fontSize:"40px"  
                        },  
                        style: {//覆盖在绘图区的加载页面的样式  
                            position: 'absolute',   
                            backgroundColor: 'white',   
                            opacity: 0.5,   
                            textAlign: 'center',  
                            color:'red'  
                        }   
                    },  
                    credits: {   
                        enabled: false       
                    },  
                    series: []  
                }  
                var oChart = null;  
                oChart = new Highcharts.Chart(options);  
                Load_SeriesData();  
              function Load_SeriesData(){  
                   oChart.showLoading("Loading....");   
                    $.ajax({  
                        type : 'GET',    
                        url : '../WebRoot/WEB-INF/json/data.json',  
                        dataType : 'json',  
                        success : function(Data){  
                            console.log(Data);  
                            for(i=0; i<Data.length;i++){  
                                var DataSeries = {  
                                    name: Data[i].name,  
                                    data: Data[i].arc  
                                };  
                                oChart.addSeries(DataSeries);  
                            }  
                            oChart.hideLoading("Loading....");
                        }  
                    });     
                }  
        });  
        </script>  
    </head>  
    <body>  
        <div id="container" style="min-width:400px;height:400px"></div>  
    </body>  
</html> 

---json部分:

[
        {
            "name" : "微信",
               "arc" : [ 0,0,0,0,0,0,0,0,0,0,9900,0]    
        },
        {
            "name" : "支付宝",
            "arc" : [ 0,0,0,0,0,0,0,0,0,20000,0,1100]
        }]

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

伯先知

您的鼓励就是我创作的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值