2016-03-04 109 views
0

我在過去使用HighCharts函數生成了許多腳本,但由於某些原因,我正在處理當前腳本,我已經失去了這個陰謀。HighCharts沒有顯示圖表

我有一個運行MySQL查詢併產生以下結果的腳本:

get_data.php

[{"name":"Room","data":[1267,1268,2371,1254,2374,1364,1378,1385,2372,2242,256,2237,2254,2261,2260,2273,2271,2268,2253,2379,2378,2377,2376,2233,2234,2243,2380,2383,2107,2108,2240,2246,2359,2381,2384,2361,2373,2395,1369,2398,2393,2391,2390,2387,2363,2109,2238,2239,2247,2248,2249,2251,2265,2266,2133,2117,2119,2118,2120,2106,2103,2101,2263,2389,2375,2369,2235,2258,1253,1266,1238,2264,2110,2114,2115,2394,2399]}] 

然後我有一個調用SCRIPT1應展示的圖表的腳本。

圖腳本:

$(function() { 

var categories=[]; 
var data2 =[]; 


var chart; 
$(document).ready(function() { 

    $.getJSON("get_data.php", function(json) { 
    $.each(json,function(i,el) { 
    if (el.name=="Room") 
    categories = el.data; 
    else data2.push(el); 
    }); 



    $('#container1').highcharts({ 
     chart: { 
      renderTo: 'container', 
      type: 'column', 
      marginTop: 80, 
      marginRight: 30, 
      marginBottom: 100, events :{ 
        load: function(){ 
        this.series[1].hide(); 
        } 
       } 
     }, 
     title: { 
      text: '', 
      x: -20, //center 
      style: { 
      fontFamily: 'Tahoma', 
      color: '#000000', 
      fontWeight: 'bold', 
      fontSize: '11px' 
      } 
     }, 
     subtitle: { 
      text: '', 
      x: -20 
     }, 
     xAxis: { 
      categories: categories, 
      labels: { 
      style: { 
       color: '#F00', 
       font: '9px Tahoma, Verdana, sans-serif' 
      } 
      } 
     }, 
     yAxis: { 
      max:100, 
      showFirstLabel: false, 
      lineColor:'#999', 
      lineWidth:1, 
      tickColor:'#666', 
      tickWidth:1, 
      tickLength:2, 
      tickInterval: 10, 
      gridLineColor:'#ddd', 
      title: { 
       text: 'Percentage', 
       style: { 
       fontFamily: 'Tahoma', 
       color: '#000000', 
       fontWeight: 'bold', 
       fontSize: '9px' 
       } 
      }, 

       stackLabels: { 
       enabled: true, 
       y: 10, 
       formatter: function() {      
        //console.log((this.axis.series[1].yData[this.x])); 
        return (this.axis.series[1].yData[this.x]) ; 

       }, 
       style: { 
       color: '#000000', 
       font: '11px Tahoma, Verdana, sans-serif' 
       } 
      } 
     }, 

     plotOptions: { 

      series: { 
       pointWidth: 15, 
       stacking: 'normal', 
       dataLabels: { 
       enabled: true, 
       rotation: -90, 
       color: '#000000', 
       align: 'center', 
       format: '{point.y:.1f}', // one decimal 
       y: 10, // 10 pixels down from the top 
       style: { 
        fontSize: '9px', 
        textShadow: false, 
        fontFamily: 'Verdana, sans-serif' 
        } 
       } 
      } 

     }, 

     tooltip: { 
      formatter: function() { 
        return '<b>'+ this.series.name +'</b><br/>'+ 
        this.x +': '+ this.y; 
      } 
     }, 
     credits: { 
      enabled: false 
     }, 
     legend: { 
      enabled: false 
     }, 
     series: data2 

    }); 
}); 

}); 

}); 

任何人都可以看到我錯了,我需要找到我丟失的情節:-) 在advanvce許多感謝給你的時間來幫忙。

Regards

+0

你在** data2 **存儲什麼? – allu

+0

您已經顯示了** get_data **的輸出,但** data2 **的輸出是什麼?控制檯中有任何錯誤? – jlbriggs

+0

我認爲問題在於你的json中只有一個系列(名稱= Room)。換句話說,你只有類別的數據,但系列也需要一些數據,所以你實際上會在圖表上顯示一些內容;) –

回答

0

你說得對,非常感謝。我只需要另一雙眼睛,我想我看了太久。