I am extremely frustrated with trying to prune and hand over to Protovis a set of arrays only containing numbers from a set of data objects that looks something like below to draw up three separate pie charts (pv.Wedge) for each object...
myData = [{dept:"Accounting",sal:90000,equ:10000,trvl:267,extra:5000},
{dept:"Sales",sal:20000,equ:10000,trvl:3049,extra:7000},
{dept:"Consulting",sal:90000,equ:58000,trvl:983,extra:17000}];
From the documentation I m told there s little looping one needs to do in Protovis, yet I can t seem to get the myData manipulated/parsed correctly, so alas I ve resorted to explicit looping.
I ve tried many different kinds of loops but the best I ve gotten is a print out of the numbers under an empty space where I would like the pie charts to appear. I would be grateful if someone could give me a hint as to what I should be doing to achieve this. Presently I am stuck at -
function getData(dept) {
var getvals = new Array();
for(idx in dept) {
for(i in idx) {
if(idx[i]=="^[0-9]+$") {
getme.push(idx[i]);
}
}
}
return getvals;
}
// myData = myData.map(function(d) {
// var valonly = new Array();
// for(key in d) {
// if(isNaN(d[key])==false) {
// valonly.push(d[key]);
// }
// }
// return valonly;
// });
var vis = new pv.Panel()
.width(w)
.height(h)
.data(getData(myData))
vis.add(pv.Wedge)
//.data(pv.normalize(getData(myData)))
.left(100)
.bottom(100)
.outerRadius(r)
.angle(function(d) d * 2 * Math.PI)
vis.add(pv.Label)
.bottom(0)
.left(100)
.textAlign("center")
//.text(data.dept + " - " + "total: " + hrsum);
vis.render();