Pen Settings

HTML

CSS

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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                <body>
    <div class="card">
      <div class="title">Gross Domestic Product</div>
      <svg class="chart"></svg>
      <div class="notes"></div>
    </div>
  </body>
              
            
!

CSS

              
                .chart {
  margin: 0px auto;
  padding: 0px;
  background-color: white;
}

.notes {
  font-size: 12px;
  font-family: sans-serif;
  color: #003366;
  padding: 20px;
  text-align: center;
}

.title {
  font-size: 2.5em;
  font-family: sans-serif;
  color: #003366;
  text-align: center;
  padding: 15px 0px 5px 0px;
}

p {
  margin: 0;
}

.chart .mouseover {
  fill: #003366;
}

.chart rect,
.chart .mouseoff {
  fill: #088DA5;
}

.chart text {
  fill: black;
  font: 10px sans-serif;
  text-anchor: end;
}

.axis text {
  font: 15px sans-serif;
}

.axis path,
.axis line {
  fill: none;
  stroke: #000;
  shape-rendering: crispEdges;
}

.card {
  background-color: white;
  margin: 40px auto;
  padding: 0px;
  width: 1050px;
  height: 640px;
  box-shadow: 0 3px 6px 0 rgba(0, 0, 0, 0.32), 0 3px 12px 0 rgba(0, 0, 0, 0.24);
}

.tooltip {
  position: absolute;
  text-align: left;
  width: auto;
  height: auto;
  padding: 3px 5px 3px 5px;
  font: 1em sans-serif;
  border: 0px;
  border-radius: 5px;
  pointer-events: none;
  box-shadow: 3px 3px 6px rgba(0, 0, 0, 0.2);
  background-color: #383B6F ;
}

.amount {
  font-size: 1em;
  font-weight: bold;
}

.year {
  font-size: 0.8em;
  font-weight: normal;
}
              
            
!

JS

              
                var url = "https://raw.githubusercontent.com/FreeCodeCamp/ProjectReferenceData/master/GDP-data.json";

var formatCurrency = d3.format("$,.2f");

var months = ["January","Febuary","March","April","May","June","July","Augest","September","October","November","December"];

$("document").ready(function(){
	 $.getJSON(url).success(function(jsonData) {
    var data = jsonData.data;

    console.log(data);
    console.log(JSON.stringify(jsonData));

    d3.select(".notes")
      .append("text")
      .text(jsonData.description);

    var margin = {
        top: 5,
        right: 10,
        bottom: 30,
        left: 75
      },
      width = 1000 - margin.left - margin.right,
      height = 500 - margin.top - margin.bottom;

    var barWidth = Math.ceil(width / data.length);

    minDate = new Date(data[0][0]);
    maxDate = new Date(data[274][0]);

    var x = d3.time.scale()
      .domain([minDate, maxDate])
      .range([0, width]);

    var y = d3.scale.linear()
      .range([height, 0])
      .domain([0, d3.max(data, function(d) {
        return d[1];
      })]);

    var xAxis = d3.svg.axis()
      .scale(x)
      .orient("bottom")
      .ticks(d3.time.years, 5);

    var yAxis = d3.svg.axis()
      .scale(y)
      .orient("left")
      .ticks(10, "");

    var infobox = d3.select(".infobox");

    var div = d3.select(".card").append("div")
      .attr("class", "tooltip")
      .style("opacity", 0);

    var chart = d3.select(".chart")
      .attr("width", width + margin.left + margin.right)
      .attr("height", height + margin.top + margin.bottom)
      .append("g")
      .attr("transform", "translate(" + margin.left + "," + margin.top + ")");

    chart.append("g")
      .attr("class", "x axis")
      .attr("transform", "translate(0," + height + ")")
      .call(xAxis);

    chart.append("g")
      .attr("class", "y axis")
      .call(yAxis)
      .append("text")
      .attr("transform", "rotate(-90)")
      .attr("y", 6)
      .attr("dy", "0.8em")
      .style("text-anchor", "end")
      .text("Gross Domestic Product, USA");

    chart.selectAll(".bar")
      .data(data)
      .enter().append("rect")
      .attr("class", "bar")
      .attr("x", function(d) {
        return x(new Date(d[0]));
      })
      .attr("y", function(d) {
        return y(d[1]);
      })
      .attr("height", function(d) {
        return height - y(d[1]);
      })
      .attr("width", barWidth)
      .on("mouseover", function(d) {
        var rect = d3.select(this);
        rect.attr("class", "mouseover");
        var currentDateTime = new Date(d[0]);
        var year = currentDateTime.getFullYear();
        var month = currentDateTime.getMonth();
        var dollars = d[1];
        div.transition()
          .duration(200)
          .style("opacity", 0.9);
        div.html("<span class='amount'>" + formatCurrency(dollars) + "&nbsp;Billion </span><br><span class='year'>" + year + ' - ' + months[month] + "</span>")
          .style("left", (d3.event.pageX + 5) + "px")
          .style("top", (d3.event.pageY - 50) + "px");
      })
      .on("mouseout", function() {
        var rect = d3.select(this);
        rect.attr("class", "mouseoff");
        div.transition()
          .duration(500)
          .style("opacity", 0);
      });
  });
});
              
            
!
999px

Console