Skip to content

Instantly share code, notes, and snippets.

@calindotgabriel
Last active January 23, 2020 09:50
Show Gist options
  • Save calindotgabriel/1ade6f3493db435ba43d4f411b48ff38 to your computer and use it in GitHub Desktop.
Save calindotgabriel/1ade6f3493db435ba43d4f411b48ff38 to your computer and use it in GitHub Desktop.
Example of data binding on a circle, in D3
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