2013-05-29 21 views
0

我正在使用高图来绘制图表。我想像这样的小时格式x轴[00,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19, 20,21,22,23]
,也是我不想用我曾评论高图表以小时格式设置x轴值

以下类别参数的js

$('#container').highcharts({ 
       chart: { 
        zoomType: 'xy' 
       }, 

       title: { 
        text: 'Average Monthly Temperature and Rainfall in Tokyo' 
       }, 
       subtitle: { 
        text: 'Source: WorldClimate.com' 
       }, 
       xAxis: [{ 
        //categories: ['00', '01', '02', '03', '04', '05', 
         //'06', '07', '08', '09', '10', '11'] 
         labels: { 
          formatter: function() { 
          return Highcharts.dateFormat('%H', this.value); 

         }, 
         style: { 
          color: '#89A54E' 
         }, 

         } 

       }], 
       yAxis: [{ // Primary yAxis 
        labels: { 
         //format: '{value}°C', 
         style: { 
          color: '#89A54E' 
         } 
        }, 
        min:0, 
        //max:4, 
        tickInterval:2, 

        title: { 
         text: 'Temperature', 
         style: { 
          color: '#89A54E' 
         } 
        } 
       }, { // Secondary yAxis 
        title: { 
         text: 'Rainfall', 
         style: { 
          color: '#4572A7' 
         } 
        }, 
        max:240, 
        tickInterval:50, 
        labels: { 
         //format: '{value} mm', 
         style: { 
          color: '#4572A7' 
         } 
        }, 
        opposite: true 
       }], 
       tooltip: { 
        shared: true 
       }, 
       legend: { 
        layout: 'vertical', 
        align: 'left', 
        x: 120, 
        verticalAlign: 'top', 
        y: 100, 
        floating: true, 
        backgroundColor: '#FFFFFF' 
       }, 
       series: [{ 
        name: 'spent', 
        color: '#4572A7', 
        type: 'column', 
        yAxis: 1, 
        data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4], 
        tooltip: { 
         valueSuffix: '' 
        }, 



       }, { 

        name: 'click', 
        color: '#89A54E', 
        type: 'spline', 
        yAxis: 1, 
        data: msg, 
        tooltip: { 
         valueSuffix: '' 
        } 
       },{ 

        name: 'click', 
        color: '#89A54E', 
        type: 'spline', 

        data: [9.9, 1.5, 6.4, 9.2, 4.0, 6.0, 5.6, 8.5, 6.4, 4.1, 5.6, 4.4], 
        tooltip: { 
         valueSuffix: '' 
        } 
       } 

       ] 
      }); 

    } 
}); 

X轴代码:

xAxis: [{ 
       //categories: ['00', '01', '02', '03', '04', '05', 
        //'06', '07', '08', '09', '10', '11'] 
        labels: { 
         formatter: function() { 
         return Highcharts.dateFormat('%H', this.value); 

        }, 
        style: { 
         color: '#89A54E' 
        }, 

        } 

      }], 

在此先感谢

+0

我正在使用双轴图表 – user2349035

回答

6

您应该

http://api.highcharts.com/highcharts#xAxis.type http://api.highcharts.com/highcharts#plotOptions.series.pointInterval http://api.highcharts.com/highcharts#xAxis.tickInterval

plotOptions:{ 
     series:{ 
      pointStart:Date.UTC(2012,0,1), 
      pointInterval: 3600 * 1000 
     } 
    }, 
+1

但在工具提示上显示周日,1月1日01:00,我只想在第一个小时的鼠标悬停上显示数小时,它应该是00,第二个01等等。 。不完整日期 – user2349035

+0

您可以使用格式化程序:http://api.highcharts.com/highcharts#tooltip.formatter并在标签中使用dateformat。 –

+0

我尝试这种方式它不工作的工具提示:{ formatter:function(){ return''+ this.x +''; } },你可以显示到http://jsfiddle.net/jbVV6/ – user2349035