Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <body role="document">
  <center><div id="chart"> </div></center>




                /*********** STEP 1 ************
Create an svg canvas to draw on*/
var HEIGHT = 600;
var WIDTH = 600;
var svg ='#chart')
    .attr('height', HEIGHT)
    .attr('width', WIDTH);

/*********** STEP 3 ************
We can draw circles based on data*/

var DATA = [100, 300, 400, 500];

var circle = svg.selectAll('circle').data(DATA, String);
    .attr('r', 25)
    .attr('cx', function(datum) {return datum;})
    .attr('cy', 25)

/*********** STEP 5 ************
If the data changes, we can animate attributes of the data that don't exist anymore*/
var DATA = [100, 200];

var circle = svg.selectAll('circle').data(DATA, String);
// These are the circles that correspond to data no longer in the dataset [300, 400, 500]
// Let's make them red
  .attr('fill', 'red');
// These are the circles that new to the dataset [200]
// Let's make them green
    .attr('r', 25)
    .attr('cx', function(datum) {return datum;})
    .attr('cy', 25)
  .attr('fill', 'green');
// You will notice that one circle is not red or green.
// That is the circle that corresponds to the datum that did not change [100]

// The most common thing to do with circles that no longer correspond to existing data is to remove them
  .style('opacity', 0)