Reputation: 910
I am trying create d3 bar chart.using this example http://bl.ocks.org/mbostock/3943967.In this example they use Lee Byron's test data generator.I remove random numbers and put hard code values.But it now gives correct graph.Can any one tell how to remove this number generator and add array to chart.
Upvotes: 0
Views: 44
Reputation: 1836
Look at this piece of code:
var n = 4, // number of layers
m = 25, // number of samples per layer
stack = d3.layout.stack(),
layers = stack(d3.range(n).map(function() { return bumpLayer(m, .1); }))
Basically, its a stacked chart so you need to organize your data conveniently:
var data = [
// first group
{
"index":"0",
"position":"bottom",
"num_visitors":"30"
},
{
"index":"0",
"position":"middle",
"num_visitors":"10"
},
{
"index":"0",
"position":"top",
"num_visitors":"15"
},
// second group
{
"index":"1",
"position":"bottom",
"num_visitors":"56"
},
{
"index":"1",
"position":"middle",
"num_visitors":"32"
},
{
"index":"1",
"position":"top",
"num_visitors":"21"
}, ....
Upvotes: 1