2014-10-06 70 views
0

我有一張圖表顯示了根據發佈時間標籤的流程。我希望X軸從00:00開始以小時顯示時間,並在1小時之間顯示24小時至23:00的整個週期。這是問題,它只顯示00:00-22:00,我不能理解爲什麼。這裏是代碼:Highcharts 24小時制

var Chart = (function() { 
    function Chart() { 
     var _this = this; 
     this.data = { "TW": [174, 5, 278, 269, 282, 283, 271, 316, 251, 265, 273, 261, 265, 265, 45, 45, 60, 60, 46, 370, 428, 465, 404, 372], "IG": [266, 217, 221, 240, 220, 206, 193, 219, 186, 233, 213, 213, 243, 243, 109, 115, 128, 136, 196, 360, 483, 432, 382, 303], "GP": [31, 14, 13, 17, 14, 11, 8, 13, 12, 11, 20, 45, 22, 29, 17, 19, 27, 21, 18, 24, 37, 35, 20, 21], "total": 12009, "toptags": [{ "tag": "#paradisehotelSE", "count": 3600 }, { "tag": "#TV4", "count": 3240 }, { "tag": "#IdolSE", "count": 3126 }] }; 
     this.load(function() { 
      _this.googleplus = _this.getData('googleplus'); 
      _this.twitter = _this.getData('twitter'); 
      _this.instagram = _this.getData('instagram'); 

      _this.init(); 
     }); 

Chart.prototype.init = function() { 
     var hour = 3600 * 1000; 

     $('#graph').highcharts({ 
      chart: { 
       backgroundColor: 'none', 
       type: 'spline', 
       spacingBottom: 0, 
       spacingTop: 0, 
       spacingLeft: 1, 
       spacingRight: 1, 
       width: null, 
       height: 270, 
       animation: 2000 
      }, 
      title: { 
       text: '' 
      }, 
      subtitle: { 
       text: '' 
      }, 
      legend: { 
       enabled: false 
      }, 
      credits: { 
       enabled: false 
      }, 
      xAxis: { 
       labels: { 
        y: 12, 
        align: 'left', 
        style: { 
         color: 'white', 
         fontWeight: 'normal', 
         fontFamily: 'Open Sans' 
        } 
       }, 
       showLastLabel: false, 
       tickmarkPlacement: 'on', 
       tickPosition: 'inside', 
       tickWidth: 0, 
       tickPixelInterval: 60, 
       lineWidth: 2, 
       lineColor: 'rgba(255,255,255,0.6)', 
       maxPadding: 0, 
       minPadding: 0, 
       gridLineWidth: 0, 
       offset: 20, 
       startOnTick: true, 
       type: 'datetime', 
       dateTimeLabelFormats: { 
        day: '%H:%M' 
       } 
      }, 
      yAxis: { 
       minorTickPosition: 'inside', 
       gridLineColor: 'rgba(255,255,255,0.3)', 
       gridLineWidth: 0, 
       title: { 
        enabled: false, 
        text: 'Temperature' 
       }, 
       labels: { 
        enabled: false 
       } 
      }, 
      tooltip: { 
       backgroundColor: 'rgba(0,0,0,0.0)', 
       borderColor: 'none', 
       shadow: false, 
       style: { 
        color: 'white', 
        fontSize: '12px', 
        padding: '8px' 
       }, 
       enabled: true, 
       crosshairs: false, 
       shared: false, 
       snap: 30, 
       formatter: function() { 
        return Math.floor(this.y); 
       } 
      }, 
      plotOptions: { 
       flags: { 
        shape: 'squarepin' 
       }, 
       spline: { 
        dashStyle: 'ShortDot', 
        lineWidth: 4 
       } 
      }, 
      series: [ 
       { 
        pointStart: 0 * hour, 
        pointInterval: hour, 
        color: '#fda345', 
        name: 'Google plus', 
        marker: { enabled: false }, 
        data: this.googleplus 
       }, 
       { 
        pointStart: 0 * hour, 
        pointInterval: hour, 
        color: '#00aced', 
        name: 'Twitter', 
        marker: { enabled: false }, 
        data: this.twitter 
       }, 
       { 
        pointStart: 0 * hour, 
        pointInterval: hour, 
        color: '#f49ac1', 
        name: 'Instagram', 
        marker: { enabled: false }, 
        data: this.instagram 
       }] 
     }); 

這是所有與圖表相關的Javascript,非常感謝您的關注。

+0

這個問題是不可能回答,不知道你的數據是什麼樣的... – Mark 2014-10-06 18:35:18

+0

對不起,添加了數據! – Daphen 2014-10-06 19:29:27

回答

3

您的圖確實顯示22:00至23:00的數據。不過,問題在於23點報時被壓制。

爲什麼?問題一,你已告訴高分榜startOnTick,但你還沒有啓用相應的endOnTickoption。問題二,你的maxPadding選項。通過將其設置爲0並且數據在23:00結束,您已給Highcharts沒有空間添加最後一個刻度標籤。

//maxPadding: 0, 
endOnTick: true 

這是fiddle

+0

非常感謝! :) – Daphen 2014-10-06 19:58:35

+0

是否可以使圖形一路走到圖表的最後?它在圖表中間結束時看起來有點突兀。 :) – Daphen 2014-10-07 06:38:38

+0

@Daphen,我也想念你將'showLastLabel'選項設置爲false。這是壓制'23:00'標籤。把它拿出來:http://jsfiddle.net/e0p69ra5/2/。你應該嘗試將這些選項縮減爲你真正需要的選項。 – Mark 2014-10-07 13:01:48