2013-08-29 158 views
3

flot饼图显示默认情况下的项目标签百分比,但我需要显示组成百分比而不是百分比的数字。下面的代码是我的数据和flot饼图标签

var pieOptions={ 
    series: { 
     pie: { 
      show: true, 
      radius: 1, 
      label: { 
       show: true, 
       radius: 3/4, 
       formatter: labelFormatter, 
       background: { 
        opacity: 0.5, 
        color: '#000' 
       } 
      } 
     } 
    }, 
    grid: { 
     hoverable: true, 
     clickable: true 
    }, 
    legend: { 
     container: '#pieLegend' 
    } 
} 

标签格式

function labelFormatter(label, series) { 
    return "<div style='font-size:8pt; text-align:center; padding:2px; color:white;'>" 
+ label + "<br/>" + Math.round(series.percent) + "%</div>"; 
} 

我的数据

[["ebbok1","1"],["ebook2","4"],["ebook3","4"],["something","3"]] 

,所以我需要1,4,4,3的饼图上显示,而不是的计算百分比

编辑

我只是想series.data[0][1],但它在图表中显示空白

回答

8

更改labelFormatter到:

function labelFormatter(label, series) { 
    return "<div style='font-size:8pt; text-align:center; padding:2px; color:white;'>" + label + "<br/>" + series.data[0][1] + "%</div>"; 
} 

,在该系列中的第一个(只)点的Y数据。