Built with blockbuilder.org
Created
April 6, 2020 18:09
-
-
Save jwilber/6ce2dffe79d2b0bf6b8983e3a706e098 to your computer and use it in GitHub Desktop.
fresh block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: mit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<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; } | |
.bar { | |
float: left; | |
width: 30px; | |
margin-right: 20px; | |
background-color: red; | |
border: 1px solid #C5C5C5; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="chart"> | |
<div class="bar"></div> | |
<div class="bar"></div> | |
<div class="bar"></div> | |
<div class="bar"></div> | |
</div> | |
<script> | |
let numbers = [15, 8, 42, 4, 32]; | |
let update = () => { | |
let selection = d3.select('#chart') | |
.selectAll('.bar').data(numbers) | |
.style('height', d => `${d}px`) | |
.style('margin-top', d => `${100 - d}px`) | |
selection.enter() | |
.append('div') | |
.attr('class', 'bar') | |
.style('height', d => `${d}px`) | |
.style('margin-top', d => `${100 - d}px`) | |
.on('click', (e, i) => { | |
numbers.splice(i, 1) | |
update() | |
}) | |
selection.exit().remove() | |
} | |
update() | |
</script> | |
</body> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment