Built with blockbuilder.org
xxxxxxxxxx
<head>
<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; }
</style>
</head>
<body>
<script>
const margin = {top: 20, left: 20, right: 100};
let svg = d3.select("body").append("svg")
.attr("width", window.innerWidth)
.attr("height", window.innerHeight)
//.append('g')
//.attr('transform', `translate(${margin.left}, ${margin.top})`);
let x = d3.scaleLinear().domain([0, 100]).range([0, window.innerWidth - margin.right]).clamp(true)
let y = d3.scaleLinear().domain([0, 100]).range([0, window.innerHeight])
svg.append('line')
.attr('x1', 0)
.attr('y1', 0)
.attr('x2', 0)
.attr('y2', 0)
.classed('line', true)
.style('stroke', 'rgb(231, 93, 135)')
.style('stroke-width', 5);
svg.on('mousemove', () => {
d3.select('.line')
.attr('x2', x(x.invert(d3.event.x)))
.attr('y2', y(y.invert(d3.event.y)))
console.log('x event',d3.event.x)
console.log('x invert',x.invert(d3.event.x))
console.log('x ()',x(x.invert(d3.event.x)))
console.log('y',y.invert(d3.event.y))
});
svg.call(d3.axisTop(x))
</script>
</body>
https://d3js.org/d3.v4.min.js