2013-05-29 48 views
1

我想將JSON文件加載到highcharts中。但是,我無法理解如何去做。 y軸標籤的年份值從2046將JSON文件加載到highcharts中繪製折線圖

開始JSON文件如下:

{ 
    "year":[2046,2047,2048,2049,2050,2051,2052,2053,2054,2055,2056,2057,2058,2059,2060,2061,2062,2063,2064,2065,2066,2067,2068], 
    "bus":[4159,458,413,606,1168,850,486,608,899,872,494,1203,868,432,732,753,1528,1564,1419,1843,1888,1610,1016], 
    "mini_bus":[2064,226,148,185,77,83,82,175,130,19,122,250,475,298,237,285,663,806,1179,593,780,1370,602], 
    "crane":[8969,800,1524,1491,1740,1629,1151,907,1291,978,829,1271,1798,1212,1477,1592,2263,3278,3594,3643,4524,1969,593], 
    "car":[24050,1893,2115,2266,3049,3043,5261,2993,4139,2507,3647,5152,4374,2906,7079,4781,5114,5156,4741,6857,12268,8510,5403], 
    "pick_up":[0,0,0,0,0,0,0,0,0,0,0,0,0,581,478,0,36,736,1588,1287,1975,3087,1208], 
    "micro":[0,0,0,0,0,0,0,0,0,0,0,0,0,232,884,584,66,138,31,128,145,115,61], 
    "tempo":[2359,856,1207,62,154,241,117,185,344,388,789,232,248,17,16,48,60,12,18,20,9,2,6], 
    "motorcycle":[35776,4954,8154,7608,8653,9401,13855,12633,12306,17090,19755,29291,38522,29404,26547,31093,45410,72568,69666,83334,168707,138907,90305], 
    "tractor":[6769,788,548,262,1396,1814,2183,1257,1265,2248,2542,3519,3189,2485,2191,1374,635,2942,3297,4663,11460,7937,2512], 
    "others":[102,1549,358,381,372,353,58,352,51,37,102,77,86,43,58,21,0,1535,206,202,31,133,73], 
    "total":[84248,11524,14467,12861,16609,17414,23193,19110,20425,24139,28280,40995,49560,37610,39699,40531,55775,88735,85739,102570,201787,163640,101779], 
    "cumulative_total":[84248,95772,110239,123100,139709,157123,180316,199426,219851,243990,272270,313265,362825,400435,440134,480665,536440,625175,710914,813484,1015271,1178911,1280690] 
} 

請幫助!

+0

看看演示,他們是在做什麼很清楚:HTTP://的jsfiddle。 net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/line-basic/ – ktm5124

+0

我已經看過演示了。我需要加載一個JSON文件,而不是使用$ .getJSON方法,然後用highcharts顯示它。 –

+0

爲什麼你不能使用getJSON? –

回答

0

它是系列或數據JSON?因爲你有JSON的incorrest圖,請大家看怎麼系列的對象應該是這樣的:

http://jsfiddle.net/QQDWG/

在情況下,當你無法改變你的JSON,你應該變換改正形式。

series: [{ 
      name: 'Tokyo', 
      data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6] 
     }, { 
      name: 'New York', 
      data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5] 
     }, { 
      name: 'Berlin', 
      data: [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0] 
     }, { 
      name: 'London', 
      data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8] 
     }] 

您的源代碼的外觀如何?

0

我也有ROW格式的JSON。當我使用這個JSON時,不顯示任何內容。

[ 
    [2046,4159,2064,8969,24050,0,0,2359,35776,6769,102,84248,84248], 
    [2047,458,226,800,1893,0,0,856,4954,788,1549,11524,95772], 
    [2048,413,148,1524,2115,0,0,1207,8154,548,358,14467,110239], 
    [2049,606,185,1491,2266,0,0,62,7608,262,381,12861,123100], 
    [2050,1168,77,1740,3049,0,0,154,8653,1396,372,16609,139709], 
    [2051,850,83,1629,3043,0,0,241,9401,1814,353,17414,157123], 
    [2052,486,82,1151,5261,0,0,117,13855,2183,58,23193,180316], 
    [2053,608,175,907,2993,0,0,185,12633,1257,352,19110,199426], 
    [2054,899,130,1291,4139,0,0,344,12306,1265,51,20425,219851], 
    [2055,872,19,978,2507,0,0,388,17090,2248,37,24139,243990], 
    [2056,494,122,829,3647,0,0,789,19755,2542,102,28280,272270], 
    [2057,1203,250,1271,5152,0,0,232,29291,3519,77,40995,313265], 
    [2058,868,475,1798,4374,0,0,248,38522,3189,86,49560,362825], 
    [2059,432,298,1212,2906,581,232,17,29404,2485,43,37610,400435], 
    [2060,732,237,1477,7079,478,884,16,26547,2191,58,39699,440134], 
    [2061,753,285,1592,4781,0,584,48,31093,1374,21,40531,480665], 
    [2062,1528,663,2263,5114,36,66,60,45410,635,0,55775,536440], 
    [2063,1564,806,3278,5156,736,138,12,72568,2942,1535,88735,625175], 
    [2064,1419,1179,3594,4741,1588,31,18,69666,3297,206,85739,710914], 
    [2065,1843,593,3643,6857,1287,128,20,83334,4663,202,102570,813484], 
    [2066,1888,780,4524,12268,1975,145,9,168707,11460,31,201787,1015271], 
    [2067,1610,1370,1969,8510,3087,115,2,138907,7937,133,163640,1178911], 
    [2068,1016,602,593,5403,1208,61,6,90305,2512,73,101779,1280690] 
] 

出於測試目的,我已經使用在highcharts文檔中使用的類似的代碼:

$(document).ready(function() { 

    var options = { 
     chart: { 
      renderTo: 'container', 
      type: 'spline' 
     }, 
     series: [{}] 
    }; 

    $.getJSON('data.json', function(data) { 
     options.series.data = data; //using series[0] it only plots the first row of the JSON 
     var chart = new Highcharts.Chart(options); 
    }); 

});​