2015-05-26 86 views
0

我正在使用Highcharts餅圖,我想爲每個點添加自定義後綴。比如現在我有這樣的提示格式化:自定義工具提示名稱餅圖

tooltip : { formatter : function() { return 'Daily KB: <b>'+ this.point.y +'</b>'; } },

,並顯示在彈出的方式是一樣的東西,對於每個分一杯羹Daily KB: 300的。我如何修改這個,使得在一個彈出框中將會出現這樣的Daily KB: 700 remaining,另一個將是Daily KB: 300

Highcharts script: 
(function($){ 
    $(this.document).ready(function(){ 
     //get local time 
    Highcharts.setOptions({ 
      colors: ['#fa604c', '#00CC66'] 
    });; 
     myChart_d = new Highcharts.Chart({ 

    chart: { 
     height:200, 
     width:200, 
     type: 'pie', 
     animation: false, 
     renderTo: 'dailychart', 
     zoomType: 'x', 

      events: { 
      load: function() { 
       requestDataLim(); 

      } 
     } 

     }, 
    title: { 
     text: 'Daily' 
    }, 
    tooltip : { 
        formatter : function() { 
      return 'Daily KB: <b>'+ this.point.y +'</b>'; 
     } 
       }, 
    //tooltip: { 
      //shared:true 
     //}, 
     plotOptions: { 
     pie: { 
      // allowPointSelect: true, 
       cursor: 'pointer', 
       dataLabels: { 
        enabled: false, 

       }, 
      borderColor: '#A0A0A0', 
      innerSize: '40%', 

     }, 
     series:{ 
      dataLabels: { 
       style:{ fontSize: '14px', fontWeight:'bold' }, 
       enabled: true, 
       formatter: function() { 
        return Math.round(this.percentage) + ' %'; 
       }, 
       distance: -15, 
       color:'black' 
      } 
     }, 
    }, 
    credits: { 
     enabled: false 
    }, 

    series: [{ 

     name: 'DailyKB', 
     data: 
      [<?php echo join(',',$d); 
        echo ','; 
        echo join (',',$dl);?>] 




    }], 
exporting: { 
buttons: { 
    printButton: { 
     enabled: false 
    }, 
    exportButton: { 
     enabled: false 
    }  
} 

}

}); 

我讓我通過Ajax和JSON數據,目前有這樣的事情[300, 700]

+1

請分享你的整個highcharts腳本。 –

回答

0

如何轉換格式FO數據對象數組?例如:

[{y: 300, suffix: ""}, {y: 700, suffix: " remaining" }] 

然後在提示設置中添加suffix信息:

return 'Daily KB: <b>'+ this.point.y +'</b>' + this.point.options.suffix; 
+0

我希望避免這種情況,但我試過了,它工作正常!謝謝您的幫助!! – thr