2013-11-21 39 views
0

目前我有這樣的腳本。 這裏的categories1數組包含編號(1,2,...),data1數組包含x軸(3,8,2,1)的值,data2數組包含用於在工具提示中顯示的值。我想給x軸編號,工具提示顯示我的特定數組值,根據在高圖

我想在x軸上顯示categories1數組,並在tooltip中顯示data2數組的工具提示。

$(function() { 

    var jsonData = JSON.parse('[{"category":"Abc","value":3},{"category":"abc1","value":8},{"category":"abc2","value":2},{"category":"abc3","value":1}]'); 

    var categories1 = []; 
    for (var i = 1; i <= jsonData.length; i++) { 
     categories1.push(i.toString()); 
    } 
    var data1 = []; 
    var data2 = []; 
    for (var i = 0; i < jsonData.length; i++) { 
     data1.push(jsonData[i].value); 
     data2.push(jsonData[i].category); 
    } 
    colorArray = ['#4a4a4a'] 
    Highcharts.setOptions({ 
     colors: colorArray 

    }); 
    $('#containerBrandChart').highcharts({ 
     chart: { 
      type: 'column' 
     }, 
     title: { 
      text: '' 
     }, 
     subtitle: { 
      text: '' 
     }, 
     xAxis: { 
      categories: categories1, 
      labels: { 
       rotation: 30, 
       align: 'top' 
      }, 
     }, 
     yAxis: { 
      min: 0, 
      title: { 
       text: '' 
      } 
     }, 

     tooltip: { 
      headerFormat: '<span style="font-size:10px">{point.key}</span>: <b>{point.y}</b>', 
      pointFormat: '', 
      footerFormat: '', 
      borderWidth: '0', 
      borderRadius: '8px', 
      backgroundColor: '#000000', 
      shared: true, 
      useHTML: true, 
      style: { 
       height: 'auto', 
       opacity: '.8', 
       filter: 'alpha(opacity = 80)', 
       padding: '10px', 
       fontFamily: '"tele-grotesk",Arial,Helvetica,sans-serif', 
       fontWeight: 'bold', 
       color: '#ffffff', 
       fontSize: '1.125em' 
      } 
     }, 
     plotOptions: { 
      column: { 
       pointPadding: 0.2, 
       borderWidth: 0 
      }, 
      series: { 
       states: { 
        hover: { 
         enabled: false 
        } 
       }, 
       point: { 
        events: { 
         mouseOver: function (event) { 
          this.options.oldColor = this.color; 
          this.graphic.attr("fill", "#e20074"); 
          var point = this; 
          //alert(this.x+1) 
          var t = this.x + 1; 
          $("#Brand" + t).css("background-color", "#e20074") 
          $("#Brand" + t).css("color", "white") 

         }, 
         mouseOut: function (event) { 

          this.graphic.attr("fill", "#4a4a4a"); 
          this.graphic.attr("fill", this.options.oldColor); 
          var t = this.x + 1; 
          $("#Brand" + t).css("background-color", "white") 
          $("#Brand" + t).css("color", "#666666") 
         } 
        } 
       }, 
      } 
     }, 
     credits: { 
      enabled: false 
     }, 
     legend: { 
      enabled: false 
     }, 
     series: [{ 
      name: '', 
      data: data1 

     }] 
    }); 

}); 

我想顯示基於類別的x軸和工具提示顯示編號。

回答

相關問題