D3.js Stacked Bar Chart, from vertical to horizontal -


i make vertical bar chart (http://bl.ocks.org/mbostock/3886208) horizontal bar chart.

thanks help!

code examples nice.

it's matter of reversing domains, axis , rect calculations:

var y = d3.scale.ordinal()     .rangeroundbands([height, 0], .1); // y becomes ordinal  var x = d3.scale.linear()     .rangeround([0, width]); // x becomes linear  // change state group positioned in y instead of x var state = svg.selectall(".state")       .data(data)       .enter().append("g")       .attr("class", "g")       .attr("transform", function(d) { return "translate(0," + y(d.state) + ")"; });  // rect calculations become  state.selectall("rect")     .data(function(d) { return d.ages; })     .enter().append("rect")     .attr("height", y.rangeband()) // height in rangeband     .attr("x", function(d) { return x(d.y0); }) // horizontal position in stack     .attr("width", function(d) { return x(d.y1) - x(d.y0); }) // horizontal "height" of bar     .style("fill", function(d) { return color(d.name); }); 

here's full working example.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -