Last active
January 23, 2020 09:50
-
-
Save calindotgabriel/1ade6f3493db435ba43d4f411b48ff38 to your computer and use it in GitHub Desktop.
Example of data binding on a circle, in D3
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
d3.csv('data/dogs.csv').then(data => { | |
data.forEach(d => d.age = +d.age); | |
const svg = d3.select('.playground') | |
.append('svg') | |
.attr('width', 600) | |
.attr('height', 600); | |
const circles = svg.selectAll('circle') | |
.data(data); | |
circles.enter() | |
.append('circle') | |
.attr('cx', (d, i) => i * 100 + 50) | |
.attr('cy', (d, i) => 50) | |
.attr('r', (d, i) => d.age * 10) | |
.attr('fill', (d, i) => 'green') | |
circles.enter() | |
.append('text') | |
.attr('x', (d, i) => i * 100 + 25) | |
.attr('y', (d, i) => 50) | |
.attr('fill', 'tomato') | |
.text((d, i) => d.name) | |
}).catch(err => { | |
console.error(err); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment