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

Packages

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.

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

              
                <!-- https://dribbble.com/shots/1910802-Line-Chart-with-gradient  -->
<div class="traffic">
  <div id="traffic-chart"></div>
  <div class="legend">
    <span>10 AM</span>
    <span>Traffic</span>
    <span>8 PM</span>
  </div>
</div>
              
            
!

CSS

              
                @import bourbon

html, body
  height: 100%
  margin: 0
  padding: 0

body
  background: #fafafa
  font-family: 'Open Sans', Arial, sans-serif
  color: #333
  @include radial-gradient(#202a51, #111235, $fallback: #202a51)
  transform-style: preserve-3d
  
.traffic
  width: 320px
  margin: 0 auto
  position: relative
  top: 50%
  transform: translateY(-50%)
  .legend
    padding-top: 10px
    font-size: 14px
    clear: both
    span
      color: rgba(#FFFFFF, 0.6)
      text-transform: uppercase
      text-align: center
      display: inline-block
      margin-right: -5px
      width: 64%
      &:nth-child(1),
      &:nth-child(3)
        color: rgba(#FFFFFF, 0.4)
        font-weight: 300
        width: 18%
  
  svg
    border-bottom: 2px solid #2a3254
    .c3-line
      // Style for the Chart Line
      fill: none
      stroke: url(#bgGradient)!important
      // Should link to ID of the linearGradient filter
      stroke-width: 4px
      stroke-linecap: round
              
            
!

JS

              
                // Color steps for the gradient
var gradientSteps = {
  '0%': '#8dc7d2',
  '33%': '#d8b26d',
  '100%': '#f3766d'
};
var gradientDirection = 'v'; // Either Horizontal (h) or Vertical (v)
 // Change it to 'h' to see a horizontal gradient

// Initializing Chart
// Just some data and c3 options
var traffic = c3.generate({
  bindto: '#traffic-chart',
  padding: {
    left: 12,
    right: 12
  },
	size: {
		width: 320,
		height: 100
	},
	data: {
		columns: [
      ['data', 50, 70, 70, 42, 50, 80, 90, 90, 52, 22, 20, 52, 48, 42, 54, 20, 19, 24, 40, 82, 78, 52, 51, 62, 62]
     ],
		types: {
			data: 'spline'
		}
	},
	axis: {
		y: {
			show: false
		},
		x: {
			show: false
		}
	},
	legend: {
		show: false
	},
	tooltip: {
		show: false
	},
	point: {
		show: false
	}
});

// Just some interval to view "live" data
var dataInt = true;
setInterval(function() {
  if (dataInt) {
    traffic.load({
      columns: [['data', 32, 52, 60, 44, 52, 78, 92, 90, 54, 18, 8, 50, 52, 50, 54, 24, 20, 26, 44, 84, 78, 52, 55, 62, 62]]
    });
    dataInt = false;
  } else {
    traffic.load({
      columns: [['data', 50, 70, 70, 42, 50, 80, 90, 90, 52, 22, 20, 52, 48, 42, 54, 20, 19, 24, 40, 82, 78, 52, 51, 62, 62]]
    });
    dataInt = true;
  }
}, 1600);


// Create element for the SVG
function svgElement(element, attr) {
  el = $(document.createElementNS('http://www.w3.org/2000/svg', element));
  return el.attr(attr);
}

if (gradientDirection == 'v') {
  var x2 = '0%';
  var y1 = '100%';
} else if (gradientDirection == 'h') {
  var x2 = '100%';
  var y1 = '0%';
}

// Create a linearGradient and add it to the C3 SVG Chart
var grad = svgElement('linearGradient', {id: 'bgGradient', x1: '0%', x2: x2, y1: y1, y2: '0%'}).appendTo('#traffic-chart svg defs');

// Add each step to the gradient
$.each(gradientSteps, function(offset, color){
  svgElement('stop', {'style':'stop-color:'+gradientSteps[offset], 'offset': offset}).appendTo('#traffic-chart svg defs #bgGradient');
});
 
              
            
!
999px

Console