2015-04-29 99 views
4

我正在使用Highcharts,我曾經可以在側面獲得標籤..但現在不工作,我是否錯過了一些東西? 紅色箭頭是我希望像在下面的例子中Highcharts側面的X軸標籤

http://jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/bar-basic/

enter image description here

這是我使用的代碼標籤,我在一個動態的方式加入系列。

credits: { 
       enabled: false 
      }, 
      chart: { 
       type: 'bar' 
      }, 
      xAxis: { 
       categories: ['Jan', 'Feb'], 
       labels: { 
        enabled: true, 
       } 
      }, 
      yAxis: { 
       min: 0, 
       max: 100, 
       title: { 
        text: 'Score', 
        align: 'high' 
       } 
      }, 
      plotOptions: { 
       bar: { 
        dataLabels: { 
         enabled: true 
        } 
       } 
      } 
     }); 

     // Add Series 
     var detailchart = $('#chart-detail').highcharts(); 
     var categories = new Array; 

     // Set Chart Title 
     detailchart.setTitle({text: results[0].category}); 

     $.each(results, function(i, data){ 
      categories.push(data.name); 
      detailchart.addSeries({ 
       name: data.name, 
       data: [data.score] 
      }); 
     }); 

     detailchart.xAxis[0].setCategories(["1", "2"]); 
     $('#chart-detail').highcharts().reflow(); 

結果是一個數組,看起來像這樣(我得到它通過Ajax)

enter image description here

任何幫助,將不勝感激! 謝謝

+0

有沒有你的形象和的jsfiddle任何區別你聯繫?看起來和我一樣。 –

+0

確實,這就是我不明白的 – Notflip

+0

我從屏幕截圖中可以看到的最明顯的事情是,您只有數據被分配到一個類別(「我的商業機敏」)。這就可以解釋爲什麼你有四個酒吧掛在同一個x軸標籤。我也很想知道爲什麼要在圖表選項中定義一對類別,然後再用'setCategories'在代碼中再進一步。這**可能是爲什麼你的標籤顯示爲「0」,而不是你想要的名稱。 –

回答

0

只有你需要的是使用4個系列,每個系列都有單個數據點。

series: [{ 
     name: 'Year 1800', 
     data: [107] 
    }, { 
     name: 'Year 1900', 
     data: [138] 
    }, { 
     name: 'Year 2008', 
     data: [973] 
    },{ 
     name: 'Year 20098', 
     data: [973] 
    }] 

例子:http://jsfiddle.net/y9wzggc4/

+0

這在左側邊欄中也顯示爲零?不是這個名字?謝謝! – Notflip