2014-02-17 36 views
8

x軸的標籤,我有以下highchart輸出:enter image description here如何格式化highcharts

我只是想看看二月-10代替二月-10 18:00在x軸的標籤。因此,所有的xaxis標籤將像2月10日,2月12日等等。但工具提示將與輸出屏幕相同。我如何格式化xaxis以便於2月10日,2月12日等等,而不是2月10日18:00,2月12日20:00等等。

$(function() { 
    $('#container').highcharts({ 
     chart: { 
      zoomType: 'xy', 
      spacingRight: 20 
     }, 
     credits: { 
      enabled: false 
     }, 
     title: { 
      text: '' 
     }, 
     xAxis: { 
      type: 'datetime', 
      labels: { 
       overflow: 'justify' 
      }, 
      startOnTick: true, 
      showFirstLabel: true, 
      endOnTick: true, 
      showLastLabel: true, 
      categories: dateAndTimeArray, 
      tickInterval: 10, 
      labels: { 
       rotation: 0.1, 
       align: 'left', 
       step: 10, 
       enabled: true 
      }, 
      style: { 
       fontSize: '8px' 
      } 
     }, 
     yAxis: { 
      title: { 
       text: 'Measurement value' 
      } 
     }, 
     tooltip: { 
      xDateFormat: '%Y-%m-%d %H:%M', 
      shared: true 
     }, 
     legend: { 
      enabled: false 
     }, 
     plotOptions: { 
      area: { 
       fillColor: { 
        linearGradient: { 
         x1: 0, 
         y1: 0, 
         x2: 0, 
         y2: 1 
        }, 
        stops: [ 
         [0, Highcharts.getOptions().colors[0]], 
         [1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')] 
        ] 
       }, 
       lineWidth: 1, 
       marker: { 
        enabled: false 
       }, 
       shadow: false, 
       states: { 
        hover: { 
         lineWidth: 1 
        } 
       }, 
       // threshold: null 
      } 
     }, 
     series: [{ 
      type: 'line', 
      name: 'Value', 
      data: chartData, 
      marker: { 
       enabled: false 
      } 
     }] 
    }); 
}); 
+0

什麼你'dateAndTimeArray'和'chartData'陣列看喜歡?如果您可以從代碼中撥出小號碼,那將會非常有幫助 –

+0

dateAndTimeArray包含格式爲Feb-10 18:00,Feb-12 20:00等格式的所有日期和時間。 chartData是包含數值的另一個數組。例如, dateAndTimeArray = [Feb-10 18:00,Feb-10 20:00,Feb-10 22:00,...,Feb-12 20:00], 和 chartData = [93.12, 94.18,98.72,...,91.24]。 我得到了dateAndTimeArray和chartData使用ui:repeat,這是一個jsf代碼。 – Novis

+0

看到小提琴: http://jsfiddle.net/tn6Kw/8/ – Novis

回答

21

酷,試試這個:

此格式添加到您的xAxislabels對象:

xAxis { 
    ... 
    labels: { 
     ... 
     formatter: function() { 
      return this.value.toString().substring(0, 6); 
     }, 
    } 
} 

鏈接:http://jsfiddle.net/tn6Kw/9/