絮状饼图不显示(修订后的代码) [英] Flot pie chart doesn't show (revised code)
问题描述
我需要一个饼图,并找到了 Flot .它看起来简单而强大,但是我发现的所有示例都使用固定值(例如[1,2])描述了数据",但我需要显示动态数据.我有五个变量,这些变量最终必须加起来为100.我只想包括那些值> 0的变量,如果它们的总和不等于100,我想添加一个元素来显示缺失的百分比.问题是我不知道如何动态构造数据参数.
I need a pie chart and found Flot. It looks simple and powerful, but all of the examples I have found describe the "data" using fixed values (e.g. [1,2]) but I need to show dynamic data. I have five variables that must ultimately add up to 100. I want to include only those that have a value > 0, and if they don't total to 100, I want to add an element that shows the missing percent. The problem is that I don't know how to dynamically construct the data parameter.
我的代码如下.它有两个问题: 1)$ .plot什么都不做-没有错误也没有grapy 2)我不知道如何添加标签文字
My code is below. There are two problems with it: 1) The $.plot does nothing - no error and no grapy 2) I don't know how to add the label text
function updatePieChart() {
var total = 0;
var data = new Array();
var verb = "";
var dataIndex = 0;
for (var dataIndex = 0; dataIndex < 5; dataIndex++) {
var duty = "DUTY_" + (dataIndex + 1);
var d = getData(duty + "_PERCENTAGETIMESPENT");
if (isNumeric(d)) {
d = parseInt(d);
if (d > 0) {
total += d;
data[dataIndex] = new Array();
data[dataIndex].push(d);
verb = getData(duty + "_SKILL");
if (verb == "") verb = duty + dataIndex;
log(duty + dataIndex + ' value: ' + d);
}
}
}
var count = data.length;
if (total != 100) {
if (total < 100) {
var missingDataNum = 100 - total;
data[count] = new Array();
data[count].push(missingDataNum);
verb = '**MISSING**';
log(verb + missingDataNum);
}
}
$.plot($('#pieChart'), data,
{
series: {
pie: {
show: true,
}
},
legend: {
show: false
}
});
}
推荐答案
已修复.参见什么是将数据作为变量传入时jQuery Flot数据的格式.问题是我没有将数据对象正确格式化为jSON对象.
Fixed. See What is the format of jQuery Flot data when passing in the data as variables. Problem was that I wasn't formatting the data object as a jSON object correctly.
这篇关于絮状饼图不显示(修订后的代码)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!