Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ 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.


Save Automatically?

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.


                <script src=""></script>
  <div id="tooltip" class="hidden">
    <p><strong>Date: </strong><span id="date"></span></p>
    <p><strong>GDP: </strong><span id="gdp"></span></p>


                .bar:hover {
  fill: yellow;

#tooltip {
  position: absolute;
  width: 200px;
  height: auto;
  padding: 10px;
  background-color: white;
  border-radius: 10px;
  box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4);
  pointer-events: none;

#tooltip.hidden {
  display: none;

#tooltip p {
  margin: 0;
  font-family: Futura;
  font-size: 16px;
  line-height: 20px;


                document.addEventListener("DOMContentLoaded", function(event) {

  // initiate GET request to load data
  const req = new XMLHttpRequest();"GET","",true);
  req.onload = function() {
    const json = JSON.parse(req.responseText);
    // build bar chart
    const dataset =;

    const padding = 60;
    const w = window.innerWidth - padding;
    const h = window.innerHeight - padding;

    const xScale = d3.scaleTime()
    .domain([d3.min(dataset, (d) => new Date(d[0])), d3.max(dataset, (d) => new Date(d[0]))])
    .range([padding, w - padding]);

    const yScale = d3.scaleLinear()
    .domain([0, d3.max(dataset, (d) => d[1])])
    .range([h - padding, padding]);

    const svg ="body")
    .attr("width", w)
    .attr("height", h)

    .attr("transform", "rotate(-90)")
    .attr("x", -200-padding)
    .attr("y", padding * 1.3)
    .text("Gross Domestic Product");
    .attr("x", w/2 - padding*2)
    .attr("y", padding)
    .text("Federal Reserve Economic Data");
      .attr("x", (d) => xScale(new Date(d[0] )))
      .attr("y", (d) => yScale(d[1]))
      .attr("width", (w-padding)/dataset.length - 1)
      .attr("height", (d) => h - padding - yScale(d[1]))
      .attr("data-date",(d) => d[0])
      .attr("data-gdp",(d) => d[1])
      .on("mouseover", function(d) {
        let xPosition = parseFloat("x"));
        let yPosition = parseFloat("y"));"#tooltip")
          .style("left", xPosition + "px")
          .style("top", yPosition + "px")
          .text(new Date(d[0]).toDateString());"#tooltip")
          .text("$" + Number(d[1]).toLocaleString() + "b");"#tooltip").classed("hidden", false);
      .on("mouseout", () => {"#tooltip").classed("hidden", true);

    const xAxis = d3.axisBottom(xScale);

      .attr("transform", "translate(0," + (h - padding) + ")")

    const yAxis = d3.axisLeft(yScale);

      .attr("transform", "translate(" + padding + ",0)")