d3.js - Bars Charts & json -
i'm new dev d3js. value bar in json [{},{}]? me. code
[{value: 11}, { value: 111}]
thank you.
your code has multiple problems.
- you reference
names.length
names undefined. think meantjson.length
- you call
chart.selectall("rect").data(data)
data (the parameter) undefined. think meantdata(json)
you using scales directly data not values in domain expecting:
chart.selectall("rect") ... .attr("y", y) .attr("width", x)
this works if data selection has values in domain of scale. in case, data objects
value
,name
properties in domain of scales, so:chart.selectall("rect") ... .attr("y", function(d) { return y(d.name); }) .attr("width", function(d) { return x(d.value); })
similar issue text nodes:
chart.selectall("text") ... .attr("x", x) .attr("y", function(d){ return y(d) + y.rangeband()/2; } ) ... .text(string);
instead, need explicitly access object properties:
chart.selectall("text") ... .attr("x", function(d) { return x(d.value); }) .attr("y", function(d) { return y(d.name) + y.rangeband()/2; } ) ... .text(function(d){return d.name;});
here's working fiddle: http://jsfiddle.net/smrm3/
Comments
Post a Comment