JSFiddle - React, Tailwind, and code Playground
by G B
HTML
<script src="http://www.chartjs.org/assets/Chart.min.js"></script>
<div id="chartcontainer">
<div id="canvascontainer">
<canvas id="race" width="250" height="250"></canvas></div>
<div id="doughnut-legend"></div>
<span class="earth"></span>
</div>
CSS
* {
padding: 0;
margin: 0;
color: inherit;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
*,
*:before,
*:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body {
position: relative;
font-family: "proxima-nova", 'Helvetica Neue', 'Helvetica', 'sans-serif';
color: #232830;
}
#chartcontainer {
width:100%;
height:400px;
padding:25px;
}
#canvascontainer {
float:left;
padding: 50px 50px 50px 50px;
background-color:#333;
height:100%;
}
lesshat-selector {
-lh-property: 0; }
::selection{color: #dfe1e8; background: #5b90bf}
::-moz-selection{color: #dfe1e8; background: #5b90bf;
}
.aspect-ratio {
width: 100%;
padding-bottom: 40%;
position: relative;
background-color: #232830;
border-bottom: 10px solid #5b90bf;
}
header {
position: absolute;
left: 0;
width: 100%;
top: 50%;
-webkit-transform: translateY(-50%);
-moz-transform: translateY(-50%);
-o-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
text-align: center;
color: #dfe1e8;
z-index: 3;
}
header h1 {
margin-bottom: 30px;
}
header h2 {
margin-bottom: 30px;
}
@media only screen and (max-width: 600px) {
header {
color: #232830;
top: 100%;
margin-top: 10px;
padding: 40px 10px;
background-color: #fafafa;
border-bottom: 1px solid #e1e1e1;
-webkit-transform: translateY(0%);
-moz-transform: translateY(0%);
-o-transform: translateY(0%);
-ms-transform: translateY(0%);
transform: translateY(0%);
}
header h1 {
font-size: 38px;
margin-bottom: 10px;
}
header h2 {
font-size: 16px;
margin-bottom: 20px;
}
header .btn {
min-width: 136px;
font-size: 14px;
padding: 18px 20px;
margin: 0 5px;
}
}
.content-main {
background-color: #fff;
z-index: 2;
position: relative;
max-width: 1440px;
margin: 0 auto;
}
@media only screen and (max-width: 600px)...
JavaScript
var piecolors = {
"AA": "#40af49",
"Other": "#ac558a",
"MR": "#f05541",
"Hispanic": "#3ac2d0",
"Asian": "#faaf3c",
"White": "#4287b0"
};
var pieData = [{
value: 24.8,
color: piecolors["AA"],
label: "African American",
highlight: highlight(piecolors["AA"], 20)
}, {
value: 2.9,
color: piecolors["Other"],
label: "Other",
highlight: highlight(piecolors["Other"], 20)
}, {
value: 5.7,
color: piecolors["MR"],
label: "Multi-Racial, Not Hispanic",
highlight: highlight(piecolors["MR"], 20)
}, {
value: 19.1,
color: piecolors["Hispanic"],
label: "Hispanic/Latino",
highlight: highlight(piecolors["Hispanic"], 20)
}, {
value: 6.5,
color: piecolors["Asian"],
label: "Asian",
highlight: highlight(piecolors["Asian"], 20)
}, {
value: 41,
color: piecolors["White"],
label: "White/Caucasian",
highlight: highlight(piecolors["White"], 20)
}];
function highlight(col, amt) {
var usePound = false;
if (col[0] == "#") {
col = col.slice(1);
usePound = true;
}
var num = parseInt(col,16);
var r = (num >> 16) + amt;
if (r > 255) r = 255;
else if (r < 0) r = 0;
var b = ((num >> 8) & 0x00FF) + amt;
if (b > 255) b = 255;
else if (b < 0) b = 0;
var g = (num & 0x0000FF) + amt;
if (g > 255) g = 255;
else if (g < 0) g = 0;
return (usePound?"#":"") + (g | (b << 8) | (r << 16)).toString(16);
}
var helpers = Chart.helpers;
var race = new Chart(document.getElementById("race").getContext("2d")).Doughnut(pieData, {
tooltipTemplate: "<%if (label){%><%=label%>: <%}%><%= value %>%",
animateRotate: true,
segmentStrokeColor : "#333"
});
var legendHolder = document.getElementById('doughnut-legend');
legendHolder.innerHTML = race.generateLegend();
// Include a html legend template after the module doughnut itself
helpers.each(legendHolder.firstChild.childNodes, function (legendNode, index) {
helpers.addEvent(legendNode, 'mouseover', function () {
...