score:1

I figured out the answer: I had forgotten to add the following lines:

    var canvasWidth= parseInt(canvas.style("width"));
    var canvasHeight= parseInt(canvas.style("height"));

And change var y0= d3.scaleBand().paddingInner(0.1).range([0, height]); to var y0= d3.scaleBand().paddingInner(0.1).range([0, canvasHeight]);