2012-07-21 51 views
0

Ajax實現不加載對象我剛開始工作Highcharts和我試圖加載從API數據類別我已經和我似乎無法打電話給我選擇的對象,我請求Highcharts內成功

 var categories = []; 
     $.ajax({ 
      url: url, 
      data: '', 
      type: "GET", 
      contentType: "application/json; charset=utf-8", 
      dataType: "jsonp", 
      success: function (result) { 
       $.each(result, function() { 
        $.each(this.Values, function (i) { 
         var date = this.Date.substr(0, 4); 
         //console.log(date); 
         //console.log(this.Value); 
         categories[i] = this.Value 
         //console.log(categories); 
         //options.xAxis.categories.push(this.Value); 
        }); 
       }); 
       console.log(options.xAxis.categories); 
      } 
     }); 
之前設置

這裏是對象

var url = sApiURL + '/api/'; 

    $(document).ready(function() { 
     //testing for Housing_Prices 
     var chart; 
     var options = { 
      chart: { 
       renderTo: 'Housing_Prices', 
       type: 'column' 
      }, 
      title: { 
       text: 'Mean/Median prices for homes over the years' 
      }, 
      xAxis: { 
       categories: [] 
      }, 
      yAxis: { 
       min: 0, 
       title: { 
        text: 'Price' 
       } 
      }, 
      legend: { 
       layout: 'vertical', 
       backgroundColor: '#FFFFFF', 
       align: 'left', 
       verticalAlign: 'top', 
       x: 80, 
       y: 70, 
       floating: true, 
       shadow: true 
      }, 
      tooltip: { 
       formatter: function() { 
        return "$600,000 in " + this.key; 
       } 
      }, 
      plotOptions: { 
       column: { 
        pointPadding: 0.2, 
        borderWidth: 0 
       } 
      }, 
      series: [{ 
       name: 'Existing Home Median Price', 
       data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4] 

      }, { 
       name: 'Existing Condo Median Price', 
       data: [83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0, 104.3, 91.2, 83.5, 106.6, 92.3] 

      }, { 
       name: 'Existing Single Family Median Price', 
       data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2] 

      }, { 
       name: 'Starter Home Median Price', 
       data: [42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4, 60.4, 47.6, 39.1, 46.8, 51.1] 

      }, 
      { 
       name: 'Existing Home Mean Price', 
       data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2] 
      }, 
      { 
       name: 'Existing Condo Mean Price', 
       data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 400.3, 51.2] 
      }, 
      { 
       name: 'Existing Single Family Mean Price', 
       data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 200.2] 
      }] 
     }; 

回答

0

url變量是DOM就緒範圍之外,但options不是那麼它在什麼範圍內你XHR被稱爲是不可見的。

var url = sApiURL + '/api/', options; 

$(document).ready(function() { 
    //testing for Housing_Prices 
    var chart; 
    options = {