jquer 获取json数据,并且用 highcharts 实现展现

json数据格式如下:

{

   "value": [
        23,
        4,
	24,
	95,
	27,
	35,
	93,
	63,
	75,
	17,
	13,
	93,
	54,
	71,
	61,
	14,
	13,
        14,
        29
    ]

  

}

需要highcharts的dark-blue.js文件

html文件格式如下:

<!doctype html>
<html lang="en">
<head>
  <script type="text/javascript" src="http://cdn.hcharts.cn/jquery/jquery-1.8.3.min.js"></script>
  <script type="text/javascript" src="http://cdn.hcharts.cn/highcharts/highcharts.js"></script>
  <script type="text/javascript" src="http://cdn.hcharts.cn/highcharts/exporting.js"></script>
  <script type="text/javascript" src="dark-blue.js"></script>
  <script>
  $(document).ready(function() {
    $.getJSON(‘http://1.1.1.1:800/1.json‘, { }, function (json_data) {
    //左侧Javascript代码
 $(function () {                                                                     
    $(document).ready(function() {                                                  
        Highcharts.setOptions({                                                     
            global: {                                                               
                useUTC: false                                                       
            }                                                                       
        });                                                                         
                                                                                    
        var chart;                                                                  
        $(‘#container‘).highcharts({                                                
            chart: {                                                                
                type: ‘spline‘,                                                     
                animation: Highcharts.svg,             
                marginRight: 10,                                                    
                events: {                                                           
                                                                           
                }                                                                   
            },                                                                      
            title: {                                                                
                text: ‘流量图‘                                            
            },                                                                      
            xAxis: {   
    title: {                                                            
                    text: ‘时间‘                                                   
                },
                type: ‘datetime‘,                                                   
                tickPixelInterval: 150                                              
            },
   credits: {          
    enabled:false
   },  
            yAxis: {                                                                
                title: {                                                            
                    text: ‘单位/M‘                                                   
                },                                                                  
                plotLines: [{                                                       
                    value: 0,                                                       
                    width: 1,                                                       
                    color: ‘#808080‘                                                
                }]                                                                  
            },                                                                      
            tooltip: {                                                              
                formatter: function() {                                             
                        return ‘<b>‘+ this.series.name +‘</b><br/>‘+                
                        Highcharts.dateFormat("时间:"+ ‘%m-%d %H:%M:%S‘, this.x) +‘<br/>‘+
                        "数据:" + Highcharts.numberFormat(this.y, 2);                         
                }                                                                   
            },   
   
            legend: {                                                               
                enabled: false                                                      
            },                                                                      
            exporting: {                                                            
                enabled: false                                                      
            },                                                                      
            series: [{                                                              
                name: ‘实时数据‘,                                                
                data: (function() {  
                    // generate an array of random data                             
                    var data = [],                                                  
                        time = (new Date()).getTime(),                            
                      length=((json_data.value).length)+1;
      
     $.each(json_data.value, function(i, value) {      
         data.push({                                                 
                            x: time - length * 1000, 
                            y: value                                       
                        }); 
      length--;      
     });                                                                  
                    return data;                                                    
                })()                                                                
            }]                                                                      
        });                                                                         
    });                                                                             
                                                                                    
});  
}); 
});                                                                                    
  </script>
</head>
<body>
  <div id="container" style="min-width:700px;height:400px"></div>
</body>
</html>

最终展现效果如下:

时间: 2024-12-21 16:02:14

jquer 获取json数据,并且用 highcharts 实现展现的相关文章

Ajax 跨域请求 jsonp获取json数据

遇到Ajax的跨域请求出问题 找了中解决办法如下: 参考内容:http://justcoding.iteye.com/blog/1366102 由于受到浏览器的限制,该方法不允许跨域通信.如果尝试从不同的域请求数据,会出现安全错误.如果能控制数 据驻留的远程服务器并且每个请求都前往同一域,就可以避免这些安全错误.但是,如果仅停留在自己的服务器上,Web 应用程序还有什么用处呢?如果需要从多个第三方服务器收集数据时,又该怎么办? 理解同源策略 同源策略阻止从一个域上加载的脚本获取或操作另一个域上的

android通过httpClient请求获取JSON数据并且解析

android通过httpClient请求获取JSON数据并且解析:http://www.cnblogs.com/gzggyy/archive/2013/05/08/3066288.html Android--使用Http向服务器发送请求并取得返回结果,下载图片:http://www.2cto.com/kf/201307/229489.html Android系列之网络(一)----使用HttpClient发送HTTP请求(通过get方法获取数据):http://blog.csdn.net/he

获取Json数据

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="JsonSendWay.aspx.cs" Inherits="JsonSendWay" %> <% =GetJsonData()%> //代码 using System;using System.Collections.Generic;using System.Linq;using Syste

jquery用ajax方式从后台获取json数据后如何将内容填充到下拉列表

对于问题从后台获取json数据,将内容填充到下拉列表,代码非常简单,具体过程请看下面代码. 需求:url:链接     par:ID       sel:下拉列表选择器 function BuildSelectBox(url, par, sel) {  $(sel).empty();  $.getJSON(url, { id: par }, function (json, textStatus) {   for (var i = json.length - 1; i >= 0; i--) {  

pyhton 从web获取json数据 保存到本地然后再读取

从web中获取json数据直接进行处理总认为太慢.主要是从web中获取获取数据的过程有点慢. 所以就在想 假设先利用空暇时间把json数据获取并保存到本地,然后再从本地文件里读取和操作.应该就要快非常多. 这中间的主要问题就是格式的转换问题:1.将获取取的json数据序列化后保存到本地文件里:2.从文件里逐行读取数据,再将其反序列化为json格式. 详细的一个演示样例程序例如以下: [为保护个人信息,程序中的一些代码不完整] from urllib.request import urlopen;

mustache 获取json数据内数组对象指定元素的方法

由于最近项目再用mustache,因此发现了这个问题,mustache无法获取json数据内数组键值的指定索引的元素 遂上网查资料总结一下两种方法 1,数据为数组对像 var obj = [{name: 'foo'}, {name: 'bar'}]; var tmp = '{{#1}}{{name}}{{/1}}'; console.log(Mustache.render(tmp, obj)); //bar 这种方法个人觉得有一定局限性 -----参照:http://stackoverflow.

获取json数据中所有key集合

/** * 获取json数据中所有key */ function fetchResponseInfo(responseInfo){ //判断是否为空 if((!responseInfo || responseInfo.length <= 0)) { return; } //获取model var jsonCon = jQuery.parseJSON(responseInfo).model; if(!jsonCon){ return; } //获取所有key var keyArr; if(json

jquery通过ajax方法获取json数据不执行success回调

问题描述:jquery通过ajax方法获取json数据不执行success回调方法 问题原因:json格式存在问题或不符合标准写法,导致总是执行error回调方法 解决方案:使json格式务必符合下述3个标准写法:      1)键名称:用双引号括起:    2)字符串:用双引号括起:    3)数字,布尔值不需要使用双引号括起 : 注意:一定是双括号!

jQuery获取json数据实现代码

jQuery获取json数据实现代码:使用jQuery操作json数据是非常的频繁的,下面提供两端代码供大家参考之用,大家可以自行分析,以便灵活应用. /栏目 //发送ajax请求 $.getJSON( "../../../Templet/GetInfoHandler.ashx", //产生JSON数据的服务端页面 {id: "0", sid: "1;2;3", rid: Math.round(Math.random() * 10) }, //向