What happens if we change the number of datasets in the array? To test this, let's add a new helper function (called set()) to randomly generate a new set of data with a random number of elements between 1 and 10:
var set = function() {
var k = rand();
var d = [];
for (var i = 1; i < k; i++) {
d.push[i];
};
return d;
};
Modify the data function slightly. We will print to the console to validate that it is working properly:
var data = function() {
var d = set();
console.log('d', d);
return d.map(function(d,i) {
var cost = rand();
var sales = rand();
return {
category: 'category-'+i,
cost: cost,
sales: cost + sales
};
});
};
Now, if we look at http://localhost:8080 again, we can see that the visualization is working properly even with a random amount of data.