JSFiddle - React, Tailwind, and code Playground

by kmburke84

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquery.flot.js"></script>
<div id="header">
		<h2>Toggling Series</h2>
	</div>

	<div id="content">

		<div class="demo-container">
			<div id="placeholder" class="demo-placeholder" style="float:left; width:675px;"></div>
			<p id="choices" style="float:right; width:135px;"></p>
		</div>

		<p>This example shows military budgets for various countries in constant (2005) million US dollars (source: <a href="http://www.sipri.org/">SIPRI</a>).</p>

		<p>Since all data is available client-side, it's pretty easy to make the plot interactive. Try turning countries on and off with the checkboxes next to the plot.</p>

	</div>

	<div id="footer">
		Copyright &copy; 2007 - 2014 IOLA and Ole Laursen
	</div>

CSS

* {	padding: 0; margin: 0; vertical-align: top; }

body {
	background: url(background.png) repeat-x;
	font: 18px/1.5em "proxima-nova", Helvetica, Arial, sans-serif;
}

a {	color: #069; }
a:hover { color: #28b; }

h2 {
	margin-top: 15px;
	font: normal 32px "omnes-pro", Helvetica, Arial, sans-serif;
}

h3 {
	margin-left: 30px;
	font: normal 26px "omnes-pro", Helvetica, Arial, sans-serif;
	color: #666;
}

p {
	margin-top: 10px;
}

button {
	font-size: 18px;
	padding: 1px 7px;
}

input {
	font-size: 18px;
}

input[type=checkbox] {
	margin: 7px;
}

#header {
	position: relative;
	width: 900px;
	margin: auto;
}

#header h2 {
	margin-left: 10px;
	vertical-align: middle;
	font-size: 42px;
	font-weight: bold;
	text-decoration: none;
	color: #000;
}

#content {
	width: 880px;
	margin: 0 auto;
	padding: 10px;
}

#footer {
	margin-top: 25px;
	margin-bottom: 10px;
	text-align: center;
	font-size: 12px;
	color: #999;
}

.demo-container {
	box-sizing: border-box;
	width: 850px;
	height: 450px;
	padding: 20px 15px 15px 15px;
	margin: 15px auto 30px auto;
	border: 1px solid #ddd;
	background: #fff;
	background: linear-gradient(#f6f6f6 0, #fff 50px);
	background: -o-linear-gradient(#f6f6f6 0, #fff 50px);
	background: -ms-linear-gradient(#f6f6f6 0, #fff 50px);
	background: -moz-linear-gradient(#f6f6f6 0, #fff 50px);
	background: -webkit-linear-gradient(#f6f6f6 0, #fff 50px);
	box-shadow: 0 3px 10px rgba(0,0,0,0.15);
	-o-box-shadow: 0 3px 10px rgba(0,0,0,0.1);
	-ms-box-shadow: 0 3px 10px rgba(0,0,0,0.1);
	-moz-box-shadow: 0 3px 10px rgba(0,0,0,0.1);
	-webkit-box-shadow: 0 3px 10px rgba(0,0,0,0.1);
}

.demo-placeholder {
	width: 100%;
	height: 100%;
	font-size: 14px;
	line-height: 1.2em;
}

.legend table {
	border-spacing: 5px;
}

JavaScript

$(function() {

		var datasets = 
			[{"dump_week":"201206","work_week":"201206","average_workload":15},{"dump_week":"201207","work_week":"201207","average_workload":31},{"dump_week":"201201","work_week":"201208","average_workload":23},{"dump_week":"201207","work_week":"201209","average_workload":24},{"dump_week":"201207","work_week":"201306","average_workload":30},{"dump_week":"201207","work_week":"201307","average_workload":45},{"dump_week":"201207","work_week":"201408","average_workload":38},{"dump_week":"201207","work_week":"201409","average_workload":52},{"dump_week":"201207","work_week":"201510","average_workload":62},{"dump_week":"201207","work_week":"201508","average_workload":22},{"dump_week":"201207","work_week":"201604","average_workload":58},{"dump_week":"201207","work_week":"201715","average_workload":11}]
		;

		// hard-code color indices to prevent them from shifting as
		// countries are turned on/off

		var i = 0;
		$.each(datasets, function(key, val) {
			val.color = i;
			++i;
		});

		// insert checkboxes 
		var choiceContainer = $("#choices");
		$.each(datasets, function(key, val) {
			choiceContainer.append("<br/><input type='checkbox' name='" + key +
				"' checked='checked' id='id" + key + "'></input>" +
				"<label for='id" + key + "'>"
				+ val + "</label>");
		});

		choiceContainer.find("input").click(plotAccordingToChoices);

		function plotAccordingToChoices() {

			var data = [];

			choiceContainer.find("input:checked").each(function () {
				var key = $(this).attr("name");
				if (key && datasets[key]) {
					data.push(datasets[key]);
				}
			});

			if (data.length > 0) {
				$.plot("#placeholder", data, {
					yaxis: {
						min: 0
					},
					xaxis: {
						tickDecimals: 0
					}
				});
			}
		}

		plotAccordingToChoices();

		// Add the Flot version string to the footer

		$("#footer").prepend("Flot " + $.plot.version + " &ndash; ");
	});