0

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.

1 Answer 1

1

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"
}, ....
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.