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.


                <!-- Load d3.js -->
<script src=""></script>

<!-- Create a div where the circle will take place -->
<div id="dataviz_axisZoom"></div>





                    // set the dimensions and margins of the graph
    var margin = {top: 10, right: 30, bottom: 30, left: 60},
        width = 460 - margin.left - margin.right,
        height = 400 - - margin.bottom;
    // append the SVG object to the body of the page
    var SVG ="#dataviz_axisZoom")
        .attr("width", width + margin.left + margin.right)
        .attr("height", height + + margin.bottom)
              "translate(" + margin.left + "," + + ")");
    //Read the data
    d3.csv("", function(data) {
      // Add X axis
      var x = d3.scaleLinear()
        .domain([4, 8])
        .range([ 0, width ]);
      var xAxis = SVG.append("g")
        .attr("transform", "translate(0," + height + ")")
      // Add Y axis
      var y = d3.scaleLinear()
        .domain([0, 9])
        .range([ height, 0]);
      var yAxis = SVG.append("g")
      // Add a clipPath: everything out of this area won't be drawn.
      var clip = SVG.append("defs").append("SVG:clipPath")
          .attr("id", "clip")
          .attr("width", width )
          .attr("height", height )
          .attr("x", 0)
          .attr("y", 0);
      // Create the scatter variable: where both the circles and the brush take place
      var scatter = SVG.append('g')
        .attr("clip-path", "url(#clip)")
      // Add circles
          .attr("cx", function (d) { return x(d.Sepal_Length); } )
          .attr("cy", function (d) { return y(d.Petal_Length); } )
          .attr("r", 8)
          .style("fill", "#61a3a9")
          .style("opacity", 0.5)
      // Set the zoom and Pan features: how much you can zoom, on which part, and what to do when there is a zoom
      var zoom = d3.zoom()
          .scaleExtent([.5, 20])  // This control how much you can unzoom (x0.5) and zoom (x20)
          .extent([[0, 0], [width, height]])
          .on("zoom", updateChart);
      // This add an invisible rect on top of the chart area. This rect can recover pointer events: necessary to understand when the user zoom
          .attr("width", width)
          .attr("height", height)
          .style("fill", "none")
          .style("pointer-events", "all")
          .attr('transform', 'translate(' + margin.left + ',' + + ')')
      // now the user can zoom and it will trigger the function called updateChart
      // A function that updates the chart when the user zoom and thus new boundaries are available
      function updateChart() {
        // recover the new scale
        var newX = d3.event.transform.rescaleX(x);
        var newY = d3.event.transform.rescaleY(y);
        // update axes with these new boundaries
        // update circle position
          .attr('cx', function(d) {return newX(d.Sepal_Length)})
          .attr('cy', function(d) {return newY(d.Petal_Length)});