I want to set a div to have the size of the browser window and add a canvas to it which has the same size.
After reading the related stackoverflow questions, I set the size of the div with
div.chart {
position: relative;
height: 100vh;
width: 100vw;
}
and append a canvas with
let chart = d3.select("div.chart");
const width = chart.style("width");
const height = chart.style("height");
let canvas = chart
.append('canvas')
.attr('width', width)
.attr('height', height);
However, the result is, that the browser window has horizontal and vertical scroll bars.
Looking at the dimensions from the console:
Looking at the dimension of the div.chart:
Looking at the dimension of the canvas:
The complete example is here
Here are my questions:
- How do I add a full browser window div and append a same size canvas such that no scroll bars show up ?
- Why does the console screenshot show that the width and height attributes of the canvas don't match the .getBoundingClientRect() ?