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="container">
        <h1 id="title">United States Gross Domestic Product (GDP)</h1>
        <div id="chart-container">



                body {
    background: #FFD898;

#container {
    display: flex;
    flex-direction: column;
    align-items: center;    
    position: relative;
    font-family: 'Open Sans', sans-serif;
  #tooltip {
      position: absolute;
      background: #FFCE7F;
      border: #333 solid 1.px;
      padding: 10px;
      box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.75);
  .bar {
    fill : #3576B2;


                var json = "";

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

function loadJSON() {
  var req = new XMLHttpRequest();
  req.onload = function() {
    if (req.readyState == 4 && req.status == 200) {
      json = JSON.parse(req.responseText);

function renderD3BarChart() {
  const w = 960;
  const h = 800;
  padding = 50;

  // Create x and y scales
  // Scale x by date - took a while to figure this out!
  // Thanks D3.js documentation!
  var minDate = new Date([0][0]);
  var maxDate = new Date([ - 1][0]);
  const xScale = d3.scaleTime()
                   .domain([minDate, maxDate])
                   .range([padding, w - padding ]);

  // Simple linear scale for y
  const yScale = d3.scaleLinear()
                   .domain([d3.min(, (d) => d[1]), d3.max(, (d) => d[1])])
                   .range([h - padding, padding]);
  // Declare a toolTip.  The method of appending a title doesn't pass the test
  var toolTip ="#container")
                  .attr("id", "tooltip")
                  .style("visibility", "hidden");
  const svg = d3
    .attr("width", w)
    .attr("height", h);
    .attr("class", "bar")
    .attr("x", (d, i) => xScale(new Date(d[0])))
    .attr("y", d => yScale(d[1]))
    .attr("width", w /
    .attr("height", d => yScale(0) - yScale(d[1]) )
    .attr("data-date", d => d[0])
    .attr("data-gdp", d => d[1])    
    .on("mouseover", d => {
        toolTip.html(`Date: ${d[0]}<br>GDP: ${d[1]} Billion`)
               .attr("data-date", d[0])
               .style("top", `${d3.event.pageY}px`)
               .style("visibility", "visible");
    .on("mouseout", d => {"visibility", "hidden");
  // Create the xAxis
  const xAxis = d3.axisBottom(xScale);

     .attr("transform", "translate(0, " + (h - padding + 10) + ")")
     .attr("id", "x-axis")
  // Create the yAxis
  const yAxis = d3.axisLeft(yScale);
     .attr("transform", "translate(" + (padding) + ", 0)")
     .attr("id", "y-axis")