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

              
                 <header>
  <h1><a href="https://learn.freecodecamp.org/data-visualization/data-visualization-projects/visualize-data-with-a-bar-chart/" target="_blank">Visualize Data with a Bar Chart</a></h1>
  <h3>FreeCodeCamp</h3>
</header>

<div class="main">
  <div class="container">
    <div id="title">Gross Domestic Product of United States</div>
   <div class="title-lead">Units: Billions of Dollars</div>
    <div class="chart"></div>
   </div>
</div>

<!-- Footer -->
<div id="footer" class="container-fluid text-center">
    <div class="footer text-center">
        <a href="https://www.facebook.com/lindakovacsart" target="_blank"><span class="fa fa-facebook-f"></span> Facebook | </a>
        <a href="https://twitter.com/lindakovacsart" target="_blank"><span class="fa fa-twitter"></span> Twitter | </a>
        <a href="https://plus.google.com/u/1/112468176480762133222" target="_blank"><span class="fa fa-google-plus"></span> Google+ | </a>
        <a href="https://www.linkedin.com/in/lindakovacsart" target="_blank"><span class="fa fa-linkedin"></span> LinkedIn | </a>
        <a href="https://github.com/lindakovacs" target="_blank"><span class="fa fa-github"></span> GitHub | </a>
        <a href="https://www.freecodecamp.org/lindakovacs" target="_blank"><i class="fa fa-fire"></i>
            FreeCodeCamp | </a> <!-- class="fa fa-free-code-camp" -->
        <a href="https://codepen.io/lindakovacs" target="_blank"><i class="fa fa-codepen"></i>Codepen</a>
    </div>
    <div class="footer text-center">&copy 2018 Made with &#10084; by Linda Kovacs</div>
</div>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0; 
  width: 100%;
}

header {
   background: #3861F3;
   color: #fff;
   font-family: sans-serif;
   width: 100%;
}
h1, h3, p{
  text-align:center;
}
a {
    text-decoration: none;
    color: #fff;
}

#title {
  font-size: 2em;
  font-family: sans-serif;
  color: #3861F3;
  text-align: center;
  /* padding: 15px 0px 5px 0px; */
}
.title-lead {
  font-size: 20px;
  color: #3861F3;
  text-align: center;
}  
.main {
  height: 100vh;
  width: 100vw;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: sans-serif;
  background: url(https://i.pinimg.com/564x/9b/a4/91/9ba49181ec3fa9fa3f9c1a07fa9f71da.jpg);
  /* background-color: #708090; */
  background-size: 64px 128px; }
  .main .container {
    height: 650px;
    width: 900px;
    background-color: #fff;
    display: flex;
    flex-direction: column;
    padding: 20px 20px 20px 20px;
    align-self: center;
    position: relative; }
    @media (min-width: 1000px) {
      .main .container {
        box-shadow: 2px 2px 20px; } }
    .main .container #title {
      text-align: center;
      font-size: 2.5em; }
    .main .container .visHolder {
      position: absolute;
      top: 6em; }

#tooltip {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  text-align: center;
  width: 150px;
  height: 70px;
  padding: 2px;
  font: 12px;
  background: #3861F3;
  color: #fff;
  box-shadow: 1px 1px 10px;
  border-radius: 2px;
  pointer-events: none; }

.overlay {
  position: absolute;
  background: #fff;
  pointer-events: none; }

#y-axis path {
  stroke: black;
  stroke-width: 1;
  fill: none; }

#x-axis path {
  stroke: black;
  stroke-width: 1;
  fill: none; }

.info {
  font-size: 0.8em; }

#footer {
	width: 100%;
	color: #fff;
	padding: 20px;
	text-align: center;
	background-color: #000;
	font-size: 15px;
}

.footer a {
	color: #fff;
	position: relative;
	text-decoration: none;
	font-weight: bold;
}
.footer a:hover {
	color: #000;
	background-color: #fff;
}
.footer p {
	font-size: 17px;
}
              
            
!

JS

              
                var yMargin = 40,
    width = 800,
    height = 500,
    barWidth = width/275;

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

var overlay = d3.select('.chart').append('div')
  .attr('class', 'overlay')
  .style('opacity', 0);

var svgContainer =  d3.select('.chart')
    .append('svg')
    .attr('width', width + 100)
    .attr('height', height + 60);

d3.json('https://raw.githubusercontent.com/freeCodeCamp/ProjectReferenceData/master/GDP-data.json', function(err, data) {
  
  svgContainer.append('text')
    .attr('transform', 'rotate(-90)')
    .attr('x', -200)
    .attr('y', 80)
    .text('Gross Domestic Product');
  
  svgContainer.append('text')
    .attr('x', width/2 + 120)
    .attr('y', height + 50)
    .text('More Information: http://www.bea.gov/national/pdf/nipaguid.pdf')
    .attr('class', 'info');
  
  var years = data.data.map(function(item) {
    var quarter;
    var temp = item[0].substring(5, 7);
    
    if(temp === '01') {
      quarter = 'Q1';
    }
    else if (temp === '04'){
      quarter = 'Q2';
    }
    else if(temp === '07') {
      quarter = 'Q3';
    }
    else if(temp ==='10') {
      quarter = 'Q4';
    }

    return item[0].substring(0, 4) + ' ' + quarter
  });
  
  var yearsDate = data.data.map(function(item) {
    return new Date(item[0]);
  });

  var xMax = new Date(d3.max(yearsDate));
  xMax.setMonth(xMax.getMonth() + 3);
  var xScale = d3.scaleTime()
    .domain([d3.min(yearsDate), xMax])
    .range([0, width]);
  
  var xAxis = d3.axisBottom()
    .scale(xScale);
  
  var xAxisGroup = svgContainer.append('g')
    .call(xAxis)
    .attr('id', 'x-axis')
    .attr('transform', 'translate(60, 500)');
  
  var GDP = data.data.map(function(item) {
    return item[1]
  });
  
  var scaledGDP = [];
  
  var gdpMin = d3.min(GDP);
  var gdpMax = d3.max(GDP);
  
  var linearScale = d3.scaleLinear()
    .domain([0, gdpMax])
    .range([0, height]);
  
  scaledGDP = GDP.map(function(item) {
    return linearScale(item);
  });
  
  var yAxisScale = d3.scaleLinear()
    .domain([0, gdpMax])
    .range([height, 0]);
  
  var yAxis = d3.axisLeft(yAxisScale)
    
  var yAxisGroup = svgContainer.append('g')
    .call(yAxis)
    .attr('id', 'y-axis')
    .attr('transform', 'translate(60, 0)');
    
  d3.select('svg').selectAll('rect')
    .data(scaledGDP)
    .enter()
    .append('rect')
    .attr('data-date', function(d, i) {
      return data.data[i][0]
    })
    .attr('data-gdp', function(d, i) {
      return data.data[i][1]
    })
    .attr('class', 'bar')
    .attr('x', function(d, i) {
      return xScale(yearsDate[i]);
    })
    .attr('y', function(d, i) {
      return height - d;
    })
    .attr('width', barWidth)
    .attr('height', function(d) {
      return d;
    })
    .style('fill', '#3861F3')
    .attr('transform', 'translate(60, 0)')
    .on('mouseover', function(d, i) {
      overlay.transition()
        .duration(0)
        .style('height', d + 'px')
        .style('width', barWidth + 'px')
        .style('opacity', .9)
        .style('left', (i * barWidth) + 0 + 'px')
        .style('top', height - d + 'px')
        .style('transform', 'translateX(60px)');
      tooltip.transition()
        .duration(200)
        .style('opacity', .9);
      tooltip.html(years[i] + '<br>' + '$' + GDP[i].toFixed(1).replace(/(\d)(?=(\d{3})+\.)/g, '$1,') + ' Billion')
        .attr('data-date', data.data[i][0])
        .style('left', (i * barWidth) + 30 + 'px')
        .style('top', height - 100 + 'px')
        .style('transform', 'translateX(60px)');
    })
    .on('mouseout', function(d) {
      tooltip.transition()
        .duration(200)
        .style('opacity', 0);
      overlay.transition()
        .duration(200)
        .style('opacity', 0);
    });

});
              
            
!
999px

Console