forked from jadiehm's block: Horizontal 100 percent bar chart red
Last active
January 6, 2018 14:12
-
-
Save lsoudade/ae6a06aca4d6e4ade7594c97ccae1e1f to your computer and use it in GitHub Desktop.
DV_project_sex
This file contains 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
license: mit |
This file contains 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://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> | |
<script src="http://d3js.org/d3.v2.js"></script> | |
<link href="styles.css" rel="stylesheet" type="text/css" /> | |
<title>"Percent complete" bar</title> | |
<style> | |
.male { | |
fill:#6A5ACD; | |
} | |
.female { | |
fill:#ffa8b2; | |
} | |
text { | |
fill:#FFF; | |
font-family:"arial"; | |
font-size:40px; | |
font-weight:bold; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="container"></div> <!--d3 chart gets inserted in this div--> | |
<script> | |
w = 500; | |
h = 80; | |
percentage_female = 70; | |
percentage_male = 30; | |
width_female = w * percentage_female / 100 ; | |
var svgContainer = d3.select("body").append("svg") | |
.attr("width", w) | |
.attr("height", h); | |
var group = svgContainer.append("g"); | |
//Draw the Rectangle | |
var rectangle = group.append("rect") | |
.attr('class','male') | |
.attr("x", 0) | |
.attr("y", 0) | |
.attr("width", w) | |
.attr("height", h); | |
//Draw the Rectangle | |
var rectangle_female = group.append("rect") | |
.attr('class','female') | |
.attr("x", 0) | |
.attr("y", 0) | |
.attr("width", width_female) | |
.attr("height", h); | |
group.append("text") | |
.attr("x", 10) | |
.attr("y", 52) | |
.text(function(d) { return percentage_female + "%"; }); | |
group.append("text") | |
.attr("x", 410) | |
.attr("y", 52) | |
.text(function(d) { return percentage_male + "%"; }); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment