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. 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


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


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 { height: 100%; }
body {
  align-items: center;
  background-color: #1D1E22;
  display: flex;
  justify-content: center;
  height: 100%;
svg {
  background-color: #fff;
  margin: 20px;
  padding: 0 0 40px 20px;

.title {
  font-size: 24px;

.bar:hover {
  fill: #333 !important;

div.tooltip {
  background: rgba(112, 127, 140, .85);
  border: none;
  border-radius: 2px;
  color: #fff;
  font-size: 24px;
  padding: 5px;
  pointer-events: none;
  position: absolute;
  text-align: center;
  width: 200px;

#x-axis .tick line {
  display: none;


                // store data in variable
const dataURI = ''

// set up svg
const w = 1120
const h = 500
const padding = 60

const svg ='body')
              .attr('width', w)
              .attr('height', h)

// set up chart title
   .attr('transform', `translate(${w/2}, ${padding})`)
   .attr('class', 'title')
   .attr('id', 'title')
   .style('text-anchor', 'middle')
   .text('United State GDP')

// get data
d3.json(dataURI, {crossOrigin: "anonymous"}).then(data => {
  // set up function to handle date parsing
  const dateFormat = d3.timeParse('%Y-%m-%d')
  // map over data for GDP values
  const GDP = => item[1])
  const dates = => item[0])
  const years = => dateFormat(date).getFullYear())
  // set up x scale (used scaleBand for help determining geometry of each bar)
  const xScale = d3.scaleBand()
                   .range([padding, w - padding])
  // set up y scale with scaleLinear
  const yScale = d3.scaleLinear()
                   .domain([0, d3.max(GDP)])
                   .range([h - padding, padding])
  // set up color scale
  const colorScale = d3.scaleSequential(d3.interpolateCool)
                       .domain([d3.min(GDP), d3.max(GDP)])
  // append div for use as tooltip
  const tooltip ='body')
                .attr('class', 'tooltip')
                .attr('id', 'tooltip')
                .style('opacity', 0)
  // set up bars
     .attr('x', d => xScale(d))
     .attr('y', d => yScale(d))
     .attr('width', xScale.bandwidth())
     .attr('height', d => h - padding - yScale(d))
     .attr('fill', '#162238')
     .attr('class', 'bar')
     .attr('data-gdp', d => d)
     .attr('data-date', (d, i) => dates[i])
     .style('fill', d => colorScale(d))
     // set up mouseover to modify tooltip div
     .on('mouseover', (d, i) => {
          .style('opacity', 0.9)
       tooltip.html(`$${d3.format(',')(d)} Billion<br>${moment(dateFormat(dates[i])).format('MMM YYYY')}`)
          .attr('data-date', dates[i])
          .style('left', (d3.event.pageX) + 15 + 'px')
          .style('top', (d3.event.pageY) + 'px')
     // set up mouseout to modify tooltip div
     .on('mouseout', d => {
          .style('opacity', 0)
  // set up x axis scale
  const xAxisScale = d3.scaleLinear()
                       .domain([d3.min(years), d3.max(years)])
                       .range([padding, w - padding])
  // set up x axis
  const xAxis = d3.axisBottom()
  // use call to create x axis
     .attr('transform', `translate(0, ${h - padding})`)
     .attr('id', 'x-axis')
   .attr('transform', `translate(${w/2}, ${h})`)
   .style('text-anchor', 'middle')
  // set up y axis
  const yAxis = d3.axisLeft(yScale)
  // us call to create y axis
     .attr('transform', `translate(${padding}, 0)`)
     .attr('id', 'y-axis')
  // set up y axis label
     .attr('transform', `translate(80, ${h/2})rotate(-90)`)
     .style('text-anchor', 'middle')
     .text('Gross Domestic Product')