Created
December 3, 2015 06:29
-
-
Save eMahtab/a1c626a97cd9a75b9a13 to your computer and use it in GitHub Desktop.
My Tea Consumption
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script> | |
<style> | |
div.chart{ | |
font-family:sans-serif; | |
font-size:0.7em; | |
} | |
div.bar { | |
background-color:DarkRed; | |
color:white; | |
height:3em; | |
line-height:3em; | |
padding-right:1em; | |
margin-bottom:5px; | |
text-align:right; | |
margin-left:22em; | |
} | |
div.label { | |
height:3em; | |
line-height:3em; | |
padding-right:1em; | |
margin-bottom:2px; | |
float:left; | |
width:20em; | |
text-align:right; | |
} | |
</style> | |
<script> | |
function draw(data) { | |
"use strict"; | |
console.log(data) | |
d3.select("body") | |
.append("div") | |
.attr("class", "chart") | |
.selectAll("div.bar") | |
.data(data) | |
.enter() | |
.append("div") | |
.attr("class","line") | |
d3.selectAll("div.line") | |
.append("div") | |
.attr("class","label") | |
.text(function(d){return d.day}) | |
d3.selectAll("div.line") | |
.append("div") | |
.attr("class","bar") | |
.style("width", function(d){return d.tea*50 + "px"}) | |
.text(function(d){return d.tea }); | |
d3.selectAll(".bar") | |
.style("background-color", function(d){ | |
if (d.tea <=3 ){ | |
return "#21E1BF" | |
} | |
else if (d.tea > 3 && d.tea <6){ | |
return "#EF5836" | |
} | |
else{ | |
return "#493829" | |
} | |
}) | |
} | |
</script> | |
</head> | |
<body> | |
<script> | |
d3.json('data/tea.json', draw); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment