d3.js - Bars Charts & json -


i'm new dev d3js. value bar in json [{},{}]? me. code

[{value: 11}, { value: 111}] 

http://jsfiddle.net/y8fu5/

thank you.

your code has multiple problems.

  1. you reference names.length names undefined. think meant json.length
  2. you call chart.selectall("rect").data(data) data (the parameter) undefined. think meant data(json)
  3. 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); }) 
  4. 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

Popular posts from this blog

vb.net - Alternative to the T-SQL AS keyword -

php - MySQLi binding parameters in a prepared statement doesn't work unless inserted after "WHERE" -

ios - CFRelease causing crash in iPad application -