javascript - D3: Create bar for only one string in my json -


i want create bar graph 1 of strings in json. here example of json:

var fruits = [{     kind: "grape",     color: "red",     quantity: 12,     tasty: true }, {     kind: "kiwi",     color: "brown",     quantity: 98,     tasty: true }, {     kind: "banana",     color: "yellow",     quantity: 0,     tasty: true }]; 

now, want create single bar in graph quantity.

is possible or should reformat data?

the length of bar should mean of values. here code far:

d3.select("svg").selectall("p")            .data(fruits)            .enter()            .append("rect")            .attr("x", 0)            .attr("y", 0)            .attr("width", 20)            .attr("height", function(d, i) {                 return d3.mean(fruits, function(d) {return d.quantity * 20})            }); 

that sort of gives me "one" bar right length. it's 3 bars stacked on top of eachother since x = 0 rects.

it turned out lot simpeler thought. focussed on using data create svg rects.

i solved appending single rectangle svg.

d3.select("svg").append("rect")        .attr("x", 0)        .attr("y", 0)        .attr("width", 20)        .attr("height", function(d, i) {             return d3.mean(fruits, function(d) {return d.quantity * 20})        }); 

excuse me if i've wasted time in way.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -