cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation


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.

              <h2 class= "title"></h2>
<div class="infobox">
  <p>Here is where we will say something interesting.</p>
<svg class="chart"></svg>
              .title {
  font-size: 12px;
  font-family: sans-serif;
  color: steelblue;

.infobox {
        position: absolute;
        left: 100px;
        width: 200px;
        padding: 10px;
        background-color: rgba(200,200,200,.75);
        border-radius: 5px;
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: 10px sans-serif;

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

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

  var jsonData;
  var url = 'https://www.quandl.com/api/v1/datasets/FRED/GDP.json?sort_order=asc';

  $.get(url).success(function(jsonData) {
	var data = jsonData.data;    
  var margin = {top: 20, right: 30, bottom: 30, left: 40},
    width = 960 - margin.left - margin.right,
    height = 500 - margin.top - margin.bottom;  
var barWidth = width / data.length;
    minDate = new Date(data[0][0]);
    maxDate = new Date(data[272][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 = d3.select(".infobox"); 

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

    .attr("class", "x axis")
    .attr("transform", "translate(0," + height + ")")
    .attr("class", "y axis")
    .attr("transform", "rotate(-90)")
    .attr("y", 6)
    .attr("dy", ".71em")
    .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 = d3.select(this);
         rect.attr("class", "mouseover");
     		 infobox.style("display", "block")
         				.html("Gross Domestic Product for <br/>" + new Date(d[0]) + "<br/>"  + d[1] + " Billion")	 					
 		 	.on("mouseout", function(){
     			 var rect = d3.select(this);
        	 rect.attr("class", "mouseoff");
      		infobox.style("display", "none");	
    function type(d) {
  		d[1] = +d[1]; // coerce to number
  		return d;



Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.


Loading ..................