2014-09-04 64 views
0

我正在使用highstock可以將chart_type更改爲樣條或線條。我面臨的問題是x軸類別與數據不一致,這通常不是。Highstock xAxis類別未對齊

這是的jsfiddle:http://jsfiddle.net/nishants/sg7ykLpe/1/

$(function() { 
    $('#container').highcharts("StockChart", { 
     chart: { 
      type: 'column',//One can change chart_type to spline or line. 
      inverted:0 
     }, 
     title: { 
      text: 'Title of the chart', 
      style: { 
       fontFamily: "lato" 
      } 
     }, 
     subtitle: { 
      text: '', 
      style: { 
       fontFamily: "lato" 
      } 
     }, 

     yAxis: 
     { 
      gridLineWidth: 0, 

      title: { 
       text: '', 
      }, 
      labels:{ 
       enabled:0, 
       formatter: function() { 
        return this.value; ; 
       } 
      }, 
      stackLabels:{ 
       enabled:0 
      }, 

      //min:1,// Avoided generally so in if clause, to handle specific cases. 


     }, 
     tooltip: { 
      enabled: 1, 
      formatter: function() { 
       return new Date(this.x).toDateString(); ; 
      } 
     }, 
     legend:{ 
      enabled:1 
     }, 
     plotOptions: { 
      column: { 
       dataLabels: { 

        color: 'white', 

        enabled: 1, 
        style: { 
         //textShadow: '0 0 3px white, 0 0 3px white' 
        }, 


        formatter:function(){ 
         if (this.y) return this.y; 
        }, 
        y:0 
        //color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || '#wihte', 


       }, 
       enableMouseTracking: true 
      }, 
      series: { 

        stacking: 'normal', //null , normal , percent 

      } 
     }, 
     series: [{'color': '#009add', 'data': [[1385625600000, 0], [1408003200000, 0], [1408348800000, 0], [1408521600000, 3], [1408608000000, 0]], 'name': 'TYPE1'}, {'color': '#f15d22', 'data': [[1385625600000, 0], [1408003200000, 1], [1408348800000, 0], [1408521600000, 0], [1408608000000, 0]], 'name': 'TYPE2'}, {'color': '#7182a6', 'data': [[1385625600000, 1], [1408003200000, 0], [1408348800000, 0], [1408521600000, 0], [1408608000000, 0]], 'name': 'TYPE3'}, {'color': '#62a60a', 'data': [[1385625600000, 0], [1408003200000, 0], [1408348800000, 2], [1408521600000, 1], [1408608000000, 2]], 'name': 'TYPE4'}] 

     ,legend: { 
      enabled: true, 
      align: 'right', 
      //backgroundColor: '#FCFFC5', 
      //borderColor: 'black', 
      //borderWidth: 2, 
      layout: 'vertical', 
      verticalAlign: 'top', 
      y: 100, 
      shadow: true 
     }, 



    }); 
}); 
+0

它是由順序軸引起的,請參閱禁用的'ordinal'選項:http://jsfiddle.net/sg7ykLpe/2/順便說一句,它被稱爲刻度,而不是Highcharts中的類別;) – 2014-09-04 12:09:24

回答

1

使用tickPositions然後通過formatter轉換您的標籤在你的情況下的值

xAxis: { 
    // in tick position set all x axis values by this tick will come on this position  
    tickPositions: [1385625600000, 1408003200000, 1408348800000, 1408521600000, 1408608000000], 
    labels: { 
     /** then by formattor function change our tick value in desired result 
     * here we convert date string in date format like dd/mm/yy 
     **/ 
     formatter: function() { 
      return new Date(this.value).getDate()+"/"+(new Date(this.value).getMonth()+1)+"/"+new Date(this.value).getYear() ; 
     } 
    } 

Live DEMO