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.


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 lang="en">

  <meta charset="utf-8">

    <title>D3-Zipline: GDP Bar Graph</title>

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



                body {
  background-color: #ddd;
  background-repeat: repeat;

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

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

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

p {
  margin: 0;

.chart .mouseover {
  fill: lightsteelblue;

.chart rect,
.chart .mouseoff {
  fill: steelblue;

.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: lightsteelblue;

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

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


                $('document').ready(function() {

  var url = '';

  var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];

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

  $.get(url).success(function(jsonData) {
    var data =;


    var margin = {
        top: 5,
        right: 10,
        bottom: 30,
        left: 75
      width = 1000 - margin.left - margin.right,
      height = 500 - - 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()
      .ticks(d3.time.years, 5);

    var yAxis = d3.svg.axis()
      .ticks(10, "");

    var infobox =".infobox");

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

    var chart =".chart")
      .attr("width", width + margin.left + margin.right)
      .attr("height", height + + margin.bottom)
      .attr("transform", "translate(" + margin.left + "," + + ")");

      .attr("class", "x axis")
      .attr("transform", "translate(0," + height + ")")

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

      .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 =;
        rect.attr("class", "mouseover");
        var currentDateTime = new Date(d[0]);
        var year = currentDateTime.getFullYear();
        var month = currentDateTime.getMonth();
        var dollars = d[1];
          .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 =;
        rect.attr("class", "mouseoff");
          .style("opacity", 0);