y axis on d3.js Stacked Bar Chart -


i display y axis on d3.js stacked bar chart. can display x axis can not display y one.

here code y axis never displays. made mistake sure can not see where.

var w = 600, h = 500  var dataset = [ {"month":"jan","purchased":6,"sold":3}, {"month":"fev","purchased":7,"sold":5}, {"month":"mars","purchased":4,"sold":3}, {"month":"avr","purchased":4,"sold":2}, {"month":"mai","purchased":8,"sold":1}, {"month":"juin","purchased":3,"sold":3}, {"month":"juil","purchased":3,"sold":4}, {"month":"aou","purchased":4,"sold":2}, {"month":"sept","purchased":6,"sold":3}, {"month":"oct","purchased":6,"sold":4}, {"month":"nov","purchased":7,"sold":3}, {"month":"dec","purchased":6,"sold":3} ];  var matrix = new array();  $.each(dataset, function(i, item) { var onemonth = new array(); onemonth.push(dataset[i].month); onemonth.push(dataset[i].purchased); onemonth.push(dataset[i].sold);  matrix.push(onemonth); });  var remapped =["purchased","sold"].map(function(dat,i){ return matrix.map(function(d,ii){     return {x: ii, y: d[i+1] }; }) });    var x = d3.scale.ordinal() .domain(dataset.map(function (d) {return d.month; })) .rangeroundbands([ 0, w ], .4);  var y = d3.scale.linear() .domain([0, 15]) .range([0, h-50]);  var z = d3.scale.ordinal().range(["#e01b5d", "#eda13e"]);  var xaxis = d3.svg.axis() .scale(x) .orient("bottom");  var yaxis = d3.svg.axis() .scale(y) .orient("left");   // create canvas var svg = d3.select("#viz").append("svg:svg") .attr("class", "chart") .attr("width", w) .attr("height", h ) .append("svg:g") .attr("transform", "translate(10,470)") .call(xaxis);  var stacked = d3.layout.stack()(remapped);  x.domain(stacked[0].map(function(d) { return d.x; })); y.domain([0, d3.max(stacked[stacked.length - 1], function(d) { return d.y0 + d.y; })]);  // add group each column. var valgroup = svg.selectall("g.valgroup") .data(stacked) .enter().append("svg:g") .attr("class", "valgroup") .style("fill", function(d, i) { return z(i); });  // add rect each date. var rect = valgroup.selectall("rect") .data(function(d){return d;}) .enter().append("svg:rect") .attr("x", function(d) { return x(d.x); }) .attr("y", function(d) { return -y(d.y0) - y(d.y); }) .attr("height", function(d) { return y(d.y); }) .attr("width", x.rangeband());  svg.append("g") .attr("class", "axis") .attr("transform", "translate(20)") .call(yaxis); 

here result result

thanks help

it looks going down below chart.

here fiddle changed transform(20) transform(20, -h). scale upside down, it's there.


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -