code revision
code revision

I've changed the example from the blog about chart integration from the filtering event.
I want the sum of the salary per office.
I wonder whether my code is clumsy or is it good.
Can you suggest if it's ok or there is a more datatables idiomatic way to do that?
Anyway I think it is working.
function zip(data) {
a1 = data[0];
a2 = data[1];
a3 = [];
for(var i = 0; i < a1.length; i++) {
a3.push([a1[i], a2[i]]);
}
//console.log('a3',a3);
return a3;
}
function chartData(table) {
var counts = {};
// Count the sum of the salary for each office
$.each(zip(table
.columns( [2,5], { search: 'applied' })
.data()),
function (index, val) {
// console.log(val);
if (counts[val[0]]) {
counts[val[0]] += Number(val[1].replace(/[^0-9.-]+/g,""));
} else {
counts[val[0]] = Number(val[1].replace(/[^0-9.-]+/g,""));
}
});
// And map it to the format highcharts uses
return $.map(counts, function (val, key) {
return {
name: key,
y: val,
};
});
}
Thank you for your support
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Looks fine, and if it's working, that's the main thing
Colin