I have a study code that I am currently using:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<script src="https://d3js.org/d3.v5.min.js"></script>
</head>
<body>
<script type="text/javascript">
var svg = d3.select('body').append('svg').attr('width', 500).attr('height', 500);
var data = [30, 20, 40];
var circles = svg.selectAll('circle')
.data(data).enter()
.append('circle')
.attr('cx', (d, i) => i * 30 + 20)
.attr('cy', 30)
.attr('r', d => d / 2)
.style('fill', 'steelblue');
circles.on('mouseenter', () => {
d3.select(this).style('fill', 'red');
});
circles.on('mouseout', function() {
d3.select(this).style('fill', 'steelblue');
})
</script>
</body>
</html>
The mouseenter
function is not working, but the mouseout
function is fine.
Please tell me the difference about function()
{} with () => {}