In the breakdown example by Mike Bostock, he uses the following to generate his data. I have my data in a CSV file, thereby decrypting it and how I can eliminate it and using my own data from a CSV is the key here.
function bumpLayer(n, o) {
function bump(a) {
var x = 1 / (.1 + Math.random()),
y = 2 * Math.random() - .5,
z = 10 / (.1 + Math.random());
for (var i = 0; i < n; i++) {
var w = (i / n - y) * z;
a[i] += x * Math.exp(-w * w);
}
}
var a = [], i;
for (i = 0; i < n; ++i) a[i] = o + o * Math.random();
for (i = 0; i < 5; ++i) bump(a);
return a.map(function(d, i) { return {x: i, y: Math.max(0, d)}; });
}
It is difficult to understand, as already mentioned, especially since after that they are manipulated as follows:
n = 6, // number of layers
m = 12, // number of samples per layer
stack = d3.layout.stack(),
layers = stack(d3.range(n).map(function() { return bumpLayer(m, .1); })),
Each step is registered on the console in the example of my working code: http://tributary.io/inlet/8827504
PURPOSE: take the csv file and process it into a 2D array that d3 can handle.
Something like this that doesn't work for me could be the starting point.
var headers = ["Under $1000","$1000-$9999","$10000-19999","$20000-99999","100K - $999999","Over $1 Million"];
var myData = function(mycsv){
d3.layout.stack()(headers
.map(function(value){
return mycsv.map(function(d) {
return {x: d.Category, y: +d[value]};
});
}))
};
Thank!
* EDIT ***
d3.layout.stack() csv :
d3.csv("crimea.csv", function(crimea) {
var causes = d3.layout.stack()(["wounds", "other", "disease"].map(function(cause) {
return crimea.map(function(d) {
return {x: parse(d.date), y: +d[cause]};
});
}));
x.domain(causes[0].map(function(d) { return d.x; }));
y.domain([0, d3.max(causes[causes.length - 1], function(d) { return d.y0 + d.y; })]);
: http://bl.ocks.org/mbostock/1134768