Built with blockbuilder.org
xxxxxxxxxx
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1.0">
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; background-color:#efefef; padding: 2em;}
svg {
width: 100%;
background-color: #fff;
}
</style>
</head>
<body>
<svg></svg>
<script>
console.clear();
const svg = d3.select('svg');
const data = [58, 16, 23, 3];
const margin = {top: 20, right: 20, bottom: 20, left: 20};
const width = svg.attr('width') - margin.left - margin.right;
const height = svg.attr('height') - margin.top - margin.bottom;
const x = d3.scaleLinear()
.rangeRound([height, 0]);
const percentScale = d3.scaleLinear()
.domain([0, 100])
.range([0,1]);
console.log(percentScale(data[1]));
const chart = svg.selectAll('rect')
.data(data)
.enter().append('rect')
console.log(document.querySelector('svg').getBoundingClientRect().width);
</script>
</body>
https://d3js.org/d3.v4.min.js