Pen Settings

HTML

CSS

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

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

              
                %canvas#chart
#chartjs-tooltip
	#chartjs-tooltip__text
              
            
!

CSS

              
                 @import url('https://fonts.googleapis.com/css?family=Roboto');

html,
body {
	background: #2F3547;
	font-family: Roboto;
	overflow: hidden
}

#chart {
	height: 50%;
	width: 50%;
}
#chartjs-tooltip {
	width: 1px;
	position: absolute;
	bottom: 50%;
	transform: translateX(-.5px);
	background: white;
	text-align: center;
	transition: .3s;
	opacity: 0;
	&.active {
		opacity: 1;
	}
	&__text {
		position: absolute;
		top: -32px;
		transform: translateX(-50%);
		padding: 2px 0;
		background: white;
		border-radius: 16px;
		font-size: 12px;
		transition: .3s;
	}
}
              
            
!

JS

              
                let canvas = document.getElementById('chart'),
		ctx    = canvas.getContext('2d'),
		grad   = ctx.createLinearGradient(0, 0, 0, window.innerHeight)

// Create a background gradient.
grad.addColorStop(0, 'rgba(71, 34, 96, .7)')
grad.addColorStop(.9, 'rgba(44, 51, 233, .7)')
grad.addColorStop(1, 'rgba(44, 51, 233, .7)')

// Create a shadow line.
let shadowLine = Chart.controllers.line.extend({
    initialize: function () {
			Chart.controllers.line.prototype.initialize.apply(this, arguments)

			var ctx = this.chart.ctx
			var originalStroke = ctx.stroke
			ctx.stroke = function () {
				ctx.save()
				ctx.shadowColor = '#1a1426'
				ctx.shadowOffsetY = 5
				ctx.shadowBlur = 15
				originalStroke.apply(this, arguments)
				ctx.restore()
			}
    }
})
Chart.controllers.shadowLine = shadowLine

let dummyData = [0, 2400, 2500, 2400, 5300, 6100, 1500, 2500];
let chart = new Chart(ctx, {
	type: 'shadowLine',
	data: {
		labels: ['', 'SAT', 'SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI'],
		datasets: [{
			label: '',
			backgroundColor: grad,
			borderColor: 'rgb(193, 130, 255)',
			bezierCurve: true,
			pointBackgroundColor: 'rgba(255, 255, 255, 1)',
			pointBorderColor: 'rgba(255, 255, 255, 1)',
			pointRadius: 7,
			pointHoverRadius: 7,
			data: dummyData,
		}]
	},
	options: {
		title: {
			display: false
		},
		layout: {
			padding: {
				left: 50
			}
		},
		legend: {
			labels: {
				boxWidth: 0,
				fontColor: 'rgba(255, 255, 255)',
				fontSize: 16,
				padding: 16
			},
		},
		scales: {
			xAxes: [{
				type: 'category',
				gridLines: {
					color: 'rgba(64, 71, 91, 1)',
					borderDash: [5, 2]
				},
				ticks: {
					padding: 16
				}
			}],
			yAxes: [{
				gridLines: {
					color: 'rgba(64, 71, 91, 1)',
					borderDash: [5, 2]
				},
				ticks: {
					min: 0,
					suggestedMax: Math.max.apply(null, dummyData) + 1000,
					// Include a dollar sign in the ticks
					callback: function(value, index, values) {
							return '$' + value + '     '
					}
				}
			}]
		},
		// Code mostly copied from http://www.chartjs.org/docs/latest/configuration/tooltip.html#external-custom-tooltips
		tooltips: {
			custom: function(tooltipModel) {
				let tooltipEl     = document.getElementById('chartjs-tooltip')
				let tooltipElText = tooltipEl.querySelector('#chartjs-tooltip__text')

				// Hide if no tooltip
				if (tooltipModel.opacity === 0) {
					// tooltipEl.style.opacity = 0
					return
				}

				// Set caret Position
				tooltipEl.classList.remove('above', 'below', 'no-transform', 'active')
				if (tooltipModel.yAlign) {
					tooltipEl.classList.add(tooltipModel.yAlign)
				} else {
					tooltipEl.classList.add('no-transform')
				}

				function getBody(bodyItem) {
					return bodyItem.lines
				}

				if (tooltipModel.body) {
					let titleLines = tooltipModel.title || []
					let bodyLines  = tooltipModel.body.map(getBody)

					// `this` will be the overall tooltip
					var position = this._chart.canvas.getBoundingClientRect()

					// Display, position, and set styles for font
					tooltipEl.className += ' active'
					tooltipEl.style.top = tooltipModel.caretY - 34 + 'px'
					tooltipEl.style.height = position.height - tooltipModel.caretY + 'px'
					tooltipElText.style.width = tooltipModel.width + 'px'
					tooltipEl.style.left = position.left + tooltipModel.caretX + 'px'
					
					// Hide original tooltip
					tooltipModel.opacity = 0
					
					// Set text
					tooltipElText.innerHTML = ''
					
					for (let i = 0; i < bodyLines.length; i++) {
						var body = bodyLines[i]
						tooltipElText.innerHTML += '$' + body
					}
				}
			}
		}
	}
})
              
            
!
999px

Console