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.


                <h2 class="bx--graph-header">Bar Graph</h2>
<div class="graph-container">
	<div class="tooltip"></div>



                body {
	padding: 1rem 3%;

.bx--graph-header {
	font-weight: 300;
	font-size: 24px;

.overlay {
	fill: #3d70b2;
	opacity: .1;
	display: none;
	pointer-events: none;

.line {
	stroke-width: 2;
	stroke: #FF00FF;
	fill: none;
	pointer-events: none;

.axis path {
	stroke: #5A6872;

.tick line {
	stroke: #5A6872;

.tick text {
	fill: #5A6872;

.graph-container {
	position: relative;

.tooltip {
	font-weight: 700;
	padding-left: 1rem 2rem;
	background-color: #fff;
	position: absolute;
	box-shadow: 0 4px 8px 0 rgba(0, 0, 0, .1); 
	border: 1px solid #DFE3E6;
	padding: .25rem .5rem;
	pointer-events: none;
	display: none;
	&:after {
		content: '';
		top: 100%;
		left: 50%;
		transform: translateX(-50%);
		position: absolute;
		width: 0; 
		height: 0; 
		border-left: 5px solid transparent;
		border-right: 5px solid transparent;
		border-top: 5px solid #fff;

.y path {
	display: none;

.label {
	font-size: 10px;
	font-weight: 700;
	fill: #5A6872;
	text-anchor: middle;


                // Function to create random data in format: [date, amount]
function createData(num) {
	let data = [];
	for (var i = 0; i < num; i++) {
		const randomNum = Math.floor(Math.random() * 1000 + 1);
		let d = new Date();
		d.setDate(d.getDate() - (i * 30));
			date: d,
			amount: randomNum
	return data;

// Create + Format data
let data = createData(12).sort(function(a, b) { return -; });

// what are these and are they things that someone should edit
const margin = { top: 30, right: 20, bottom: 60, left: 65 };
const width = 800 - (margin.left + margin.right);
const height = 300 - ( + margin.bottom);
const labelOffset = 50;
const axisOffset = 16;

// Set Time Format (JAN, FEB, etc..)
const timeFormat = d3.timeFormat('%b');

// Set the scales
const x = d3.scaleBand()
	.rangeRound([0, width])
	.domain( =>

const y = d3.scaleLinear()
	.range([height, 0])
	.domain([0, d3.max(data, (d) => d.amount)]);

// // Set the axes
const xAxis = d3.axisBottom()

const yAxis = d3.axisLeft()

// // Set up SVG with initial transform to avoid repeat positioning
const svg ='svg')
		.attr('class', 'graph')
		.attr('width', width + (margin.left + margin.right))
		.attr('height', height + ( + margin.bottom))
		.attr('class', 'group-container')
		.attr('transform', `translate(${margin.left}, ${})`)
		.attr('font-family', 'ibm-plex-sans');

// // Add Y axis
	.attr('class', 'axis y')
	.attr('stroke-dasharray', '4')
	.attr("x", -axisOffset)
	.attr('font-family', 'ibm-plex-sans');

// // Add Y axis label
const yLabel ='.y')
	.text('USAGE ($)')
	.attr('class', 'label')
	.attr('transform', `translate(${-labelOffset}, ${height / 2}) rotate(-90)`)
	.attr('font-family', 'ibm-plex-sans');

// // Add X axis
	.attr('class', 'axis x')
	.attr('transform', `translate(0, ${height})`)
	.attr("y", axisOffset)
	.attr('font-family', 'ibm-plex-sans')

// // Add X axis label
const xLabel ='.x')
	.attr('class', 'label')
	.attr('transform', `translate(${width / 2}, ${labelOffset})`)
	.attr('font-family', 'ibm-plex-sans');

	.attr('class', 'bar-container')
	.attr('class', 'bar')
	.attr('x', (d) => x(
	.attr('y', (d) => height)
	.attr('height', 0)
	.attr('width', x.bandwidth())
	.attr('fill', '#00A78F')
	.delay((d, i) => i * 50)
	.attr('height', (d) => height - y(d.amount))
	.attr('y', (d) => y(d.amount));

// Select Tooltip
const tooltip ='.tooltip');
const bars = svg.selectAll('.bar')
	.on('mouseover', function(d) {	
		let color = d3.color('#00A78F').darker()
			.attr('fill', color)
			.style('display', 'inherit')
			.style('top', `${y(d.amount) - axisOffset}px`);
		let bandwidth = x.bandwidth();
		let tooltipWidth = tooltip.nodes()[0].getBoundingClientRect().width;
		let offset = (tooltipWidth - bandwidth) / 2;
			.style('left', `${x( + margin.left - offset}px`)
	.on('mouseout', function(d) {
			.attr('fill', '#00A78F')
			.style('display', 'none')