我正在使用flot库来绘制饼图。我想绘制具有图例和组合的饼图。馅饼标签。其中饼图标签只显示切片百分比&数据系列中的相应标签信息将显示在图例中。使用flot图表可以实现这种组合吗?
答案 0 :(得分: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。
答案 1 :(得分: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}
});