简体   繁体   中英

Highcharts with Ajax call returning JSON file

I am trying to use Highcharts with an external server that returns a JSON file but I cannot get the returning file to bind to the chart. I am developing the application in ASP.NET MVC

My attempt at the code is here: http://jsfiddle.net/Q6ngj/2/

jQuery.ajax({
    url: urlM4AirTemp,
    dataType: 'jsonp',
    cache: true,
    jsonp: false,
    jsonpCallback: 'ourCallbackM4AirTemp'}).done(function (airTempData) {

        var msg = airTempData.table.rows;
        var intYr;
        var intMonth;
        var intDay;
        var intHour;
        var intMin;
        var intSec;
        jQuery.each(msg,function(i,value){
        intYr = value[0].substring(0,4);
        intMonth = value[0].substring(5,7)-1;
        intDay = value[0].substring(8,10);
        intHour = value[0].substring(11,13);
        intMin = value[0].substring(14,16);
        intSec = value[0].substring(17,19);
        var d = new Date(intYr,intMonth,intDay, intHour,intMin, intSec);
        d =d.toUTCString();

        d=Date.parse(d);
        airTemp.push([d,value[1]]);
        }); 

    //Load up Graph
    options.series[0].data = airTemp;

    chart = new Highcharts.Chart(options);
});
};

Is ajax the correct method to call here or should I be using getJSON?

In first line (script at jsfiddle):

(function(){

In last:

})();

And whole json in remote file should be wrapped in ourCallbackM4AirTemp( and ); .

Two problems I see in jsFiddle:

  • jsonpCallback: ('ourCallbackM4AirTemp'); -> remove ; , it breaks js code
  • your JSONP is simple JSON, so it won't work, read about differences between JSON ans JSONP

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM