2013-09-27 101 views
2

我正在使用flot圖庫繪製餅圖。我想繪製結合了圖例&餅圖標籤的餅圖。其中餅圖標籤只會顯示切片百分比&對應的標籤信息將從數據系列中顯示出來。這個組合是否可以使用flot圖表?Flot帶有圖例和餅圖標籤的餅圖

回答

8

如果你想用百分比只(無標籤)切片,你需要定義一個定製formatter的標籤選項:

$.plot($("#placeholder"), datapie, { 
    series: { 
     pie: { 
      show: true, 
      label: { 
       show: true, 
       // Added custom formatter here... 
       formatter: function(label,point){ 
        return(point.percent.toFixed(2) + '%'); 
       } 
      } 
     } 
    },   
    legend: {show: true} 
}); 

小提琴here

enter image description here

3

是的,這是可能的,這裏有一個例子 - http://jsfiddle.net/Rnusy/11/

datapie = [ 
{label: "Running", data: 19.5, color: '#e1ab0b'}, 
{label: "Stopped", data: 4.5, color: '#fe0000'}, 
{label: "Terminated", data: 36.6, color: '#93b40f'} 
]; 


$.plot($("#placeholder"), datapie, { 

series: { 
pie: {show: true, 
    label: {show: true} 
} 
}, 

legend: {show: true} 

});