我不知道如何让flot.pie将标签中显示的数据从“原始数据”的百分比更改为实际数据。在我的例子中,我创建了一个包含已读/未读消息数量的饼图。jquery flot饼图显示数据值而不是百分比
读邮件数:50 数未读消息:150
创建的饼图显示已读邮件为25%的比例。在这一点上,我想显示实际的50条消息。见下图:
我用来创建饼图代码:
var data = [
{ label: "Read", data: 50, color: '#614E43' },
{ label: "Unread", data: 150, color: '#F5912D' }
];
和:
$(function() {
$.plot($("#placeholder"), data,
{
series: {
pie: {
show: true,
radius: 1,
label: {
show: true,
radius: 2/3,
formatter: function (label, series) {
return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">' + label + '<br/>' + Math.round(series.percent) + '%</div>';
},
threshold: 0.1
}
}
},
legend: {
show: false
}
});
});
这可能吗?
随着@Ryley的回答,我来到了一个肮脏的解决方案。当我输出series.data时,返回值“1,150”和“1,50”。我提出了减去返回值的前2个字符并显示减法值的想法。
String(str).substring(2, str.lenght)
这是饼图我用这个解决方案中创建:
这是不是最好的解决方案,但它为我工作。如果有人知道更好的解决方案....
我不能格式化工作,调试器甚至不回落到该行... – 2014-10-21 11:07:53