Skip to content

Instantly share code, notes, and snippets.

@FrankHassanabad
Created February 13, 2015 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FrankHassanabad/95f3886260c02b89ca84 to your computer and use it in GitHub Desktop.
Save FrankHassanabad/95f3886260c02b89ca84 to your computer and use it in GitHub Desktop.
Change three little circles
//On the page http://bost.ocks.org/mike/circles/
//This will change the first set of circles as an example of
//how all of that works. Paste this into your chrome console
//when on that page and then execute changeFirstCircles([4, 4, 4])
//or any other numbers you want.
var chanageFirstCircles = function(newDataSet)
{
// Generic function that binds the data
var f = function(d) { return d; }
// Get the first svg
var svg = d3.select('svg');
// Add the data
var circles = svg.selectAll('circle').data(newDataSet);
// Change the existing data
circles.attr('r', f).attr('cx', f).attr('cy', f);
// Add the new data
circles.enter().append('circle').attr('r', f).attr('cx', f).attr('cy', f);
// Remove the old data
circles.exit().remove();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment