2015-03-13 40 views
1

我還沒有看到其他人嘗試這樣做。我基本上有一組數據用於我的「系列」集合中的餅圖,但是在傳說中,而不是將這些貨幣值分出來,我想對它們進行「分類」。我認爲我之前通過在完整事件中完成點名稱的「傳說」更新,但現在似乎還在更改數據標籤名稱。這裏是我的小提琴/代碼:具有不同「名稱」的圖例和數據標籤

http://jsfiddle.net/Lyuo4f9g/1/

$(function() { 
var chart; 
$('#pie_chart').highcharts({ 
    chart: { 
     plotBackgroundColor: null, 
     plotBorderWidth: null, 
     plotShadow: false 
    }, 
    title: { 
     text: null 
    }, 
    tooltip: { 
     pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>' 
    }, 
    plotOptions: { 
     pie: { 
      allowPointSelect: true, 
      cursor: 'pointer', 
      showInLegend: true, 
      dataLabels: { 
       enabled: true, 
       defer: false, 
       format: '<b>{point.name}</b>: {point.percentage:.1f} %', 
       style: { 
        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black' 
       } 
      } 
     } 
    }, 
    colors: ['#77AEFF', '#94D664', '#E3DE51', '#D69567', '#D66664', '#aaaaab', '#a89375'], 
    legend: { 
     enabled: true 
    }, 
    series: [{ 
     type: 'pie',    
     data: [ 
      ['$64,351.70', 90.0], { 
       name: '$4,580.37', 
       y: 6.0, 
       sliced: true, 
       selected: true 
      }, ['$742.31', 1.0], 
      ['$1231.43', 2.0], 
      ['499.97', 1.0], 
      ['$74.54', 0.0], 
      ['$32.35', 0.0], 
     ] 
    }] 
}, function (chart) { // on complete 
    $(document).ready(function() { 
     chart.legend.allItems[0].update({ 
      name: 'Current' 
     }); 
     chart.legend.allItems[1].update({ 
      name: '31-60' 
     }); 
     chart.legend.allItems[2].update({ 
      name: '61-90' 
     }); 
     chart.legend.allItems[3].update({ 
      name: '91-120' 
     }); 
     chart.legend.allItems[4].update({ 
      name: '121-150' 
     }); 
     chart.legend.allItems[5].update({ 
      name: '151-180' 
     }); 
     chart.legend.allItems[6].update({ 
      name: 'Over 180' 
     }); 
    }); 
}); 

});

我基本上想要datalabels顯示貨幣值(即$ ##。##)和百分比。但傳說繼續顯示「當前,31-60等」

有什麼建議嗎?

回答

4

好的,所以我瞭解到legend屬性有一個「labelFormatter」選項,它允許您創建一種LookUp表格來標記圖例的名稱。很酷。

http://forum.highcharts.com/viewtopic.php?f=9&t=6202

所以基本上我的傳說屬性現在看起來是這樣的:

 legend: { 
     enabled: true, 
     labelFormatter: function() { 
      return { 
       '$64,351.70' : 'Current', 
       '$4,580.37': '31-60', 
       '$742.31': '61-90', 
       '$1231.43': '91-120', 
       '$499.97': '121-150', 
       '$74.54': '151-180', 
       '$32.35': 'Over 180' 
      }[this.name]; 
     } 
    },enter code here 

更新小提琴:http://jsfiddle.net/Lyuo4f9g/2/

相關問題