Skip to content

Instantly share code, notes, and snippets.

@fullstackplus
Created January 8, 2016 11:25
Show Gist options
  • Save fullstackplus/c0a25c189a8315dc70f1 to your computer and use it in GitHub Desktop.
Save fullstackplus/c0a25c189a8315dc70f1 to your computer and use it in GitHub Desktop.
Stacked bar with minimal tooltips
<!--
This is a heavily modified version of Wilson Miner's Timeline Charts example from
A List Apart #256 (http://alistapart.com/article/accessibledatavisualization). Accomodates
a list of stacked subvalues within a single bar segment.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Timeline / Accessible Data Examples</title>
<style type="text/css" media="screen">
/* SETUP */
* {
margin: 0;
padding: 0;
list-style-type: none;
}
body {
font-family: Helvetica, Arial, sans-serif;
color: #333;
}
a {
color: #2D7BB2;
text-decoration: none;
font-weight: bold;
}
a:hover {
color: #333;
}
h1, h2, h3 {
clear: both;
margin: 0 0 0.6em 0;
}
h3 {
color: #666;
}
section {
display: block; /* HTML5 shim */
width: 20em;
margin: 0 auto;
padding: 1em 2em;
}
/* TIMELINE CHARTS */
.timeline {
font-size: 3em; /* tweak to zoom in / out */
height: 10em;
width: 53em;
}
.timeline > li {
position: relative;
display: inline-block;
width: 1.5em;
height: 8em;
}
.timeline > li a {
display: block;
height: 100%;
}
.timeline > li .label {
display: block;
position: absolute;
bottom: -2.5em; /* vertical offset */
left: 0;
background: #fff;
width: 100%;
height: 2em;
line-height: 2em;
text-align: center;
font-size: .8em; /* adjust to match default */
}
ul.values {
/*
Essential to set this element's height to that of the parent — 
as its childrens' heights are sized relatively.
*/
height: 100%;
z-index: -1;
}
ul.values li {
/*text-indent: -9999px;*/
/*overflow: hidden;*/
position: relative;
}
div.tooltip {
font-size: 16px;
vertical-align: bottom;
width: 200px;
padding: 5px;
position: absolute;
bottom: 15px;
left: 35%;
z-index: 15;
border: 3px solid #000;
border-radius: 3px;
background: rgba(0,0,0, .6);
color: #2EFA05;
/*color: yellow;*/
font-family: 'Monaco';
font-size: .27em;
/*display: none;*/
visibility: hidden;
opacity: 0;
transition: visibility 0s, opacity 0.7s linear;
}
ul.values li:hover div.tooltip {
/*display: block;*/
visibility: visible;
opacity: 1;
}
dt {
float: left;
clear: left;
padding-right: 5px;
}
dt:after { content: ":"; }
dd { margin-bottom: .3em; }
.red { background: red; }
.green { background: green; }
.yellow { background: yellow; }
</style>
</head>
<body>
<article>
<section class="vertical stacked bar chart">
<h1>Timeline chart</h1>
<h2>Fruits eaten over time</h2>
<h3>December 2007</h4>
<ul class="timeline">
<li>
<a href="http://www.example.com/2007/dec/1/" title="December 1, 2007: 40">
<span class="label">1</span>
<ul class="values">
<li class="red" style="height: 20%">
<div class="tooltip">
<dl>
<dt>Date</dt>
<dd>December 1, 2007</dd>
<dt>Fruit eaten</dt>
<dd>88 (20%)</dd>
</dl>
</div>
</li>
<li class="green" style="height: 20%">
<div class="tooltip">
<dl>
<dt>Date</dt>
<dd>December 1, 2007</dd>
<dt>Fruit eaten</dt>
<dd>88 (20%)</dd>
</dl>
</div>
</li>
<li class="yellow" style="height: 60%">
<div class="tooltip">
<dl>
<dt>Date</dt>
<dd>December 1, 2007</dd>
<dt>Fruit eaten</dt>
<dd>88 (20%)</dd>
</dl>
</div>
</li>
</ul>
</a>
</li>
<li>
<a href="http://www.example.com/2007/dec/1/" title="December 1, 2007: 40">
<span class="label">2</span>
<ul class="values">
<li class="red" style="height: 70%">
<div class="tooltip">
<dl>
<dt>Date</dt>
<dd>December 1, 2007</dd>
<dt>Fruit eaten</dt>
<dd>88 (20%)</dd>
</dl>
</div>
</li>
<li class="green" style="height: 10%">
<div class="tooltip">
<dl>
<dt>Date</dt>
<dd>December 1, 2007</dd>
<dt>Fruit eaten</dt>
<dd>88 (20%)</dd>
</dl>
</div>
</li>
<li class="yellow" style="height: 20%">
<div class="tooltip">
<dl>
<dt>Date</dt>
<dd>December 1, 2007</dd>
<dt>Fruit eaten</dt>
<dd>88 (20%)</dd>
</dl>
</div>
</li>
</ul>
</a>
</li>
<li>
<a href="http://www.example.com/2007/dec/1/" title="December 1, 2007: 40">
<span class="label">3</span>
<ul class="values">
<li class="red" style="height: 5%">
<div class="tooltip">
<dl>
<dt>Date</dt>
<dd>December 1, 2007</dd>
<dt>Fruit eaten</dt>
<dd>88 (20%)</dd>
</dl>
</div>
</li>
<li class="green" style="height: 55%">
<div class="tooltip">
<dl>
<dt>Date</dt>
<dd>December 1, 2007</dd>
<dt>Fruit eaten</dt>
<dd>88 (20%)</dd>
</dl>
</div>
</li>
<li class="yellow" style="height: 40%">
<div class="tooltip">
<dl>
<dt>Date</dt>
<dd>December 1, 2007</dd>
<dt>Fruit eaten</dt>
<dd>88 (20%)</dd>
</dl>
</div>
</li>
</ul>
</a>
</li>
</ul>
</section>
</article>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment