Built with blockbuilder.org
Last active
April 9, 2017 21:30
-
-
Save trinary/de7c1c7b2e7bf2fb435846f17cb94bab to your computer and use it in GitHub Desktop.
basic bars, oriented correctly
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> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.7.4/d3.min.js"></script> | |
<style> | |
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
svg { width:100%; height: 100% } | |
</style> | |
</head> | |
<body> | |
<svg></svg> | |
<script> | |
var d = [ | |
{value: 7}, | |
{value: 20}, | |
{value: 33}, | |
{value: 9 }, | |
{value: 22 }, | |
{value: 44}, | |
{value: 15}, | |
{value: 26} | |
]; | |
var svg = d3.select("svg"); | |
// We've taken the scaling factor out into its own function | |
var yScale = function(d) { return d * 5; } | |
var bars = svg.selectAll(".bars") | |
.data(d); | |
bars.enter() | |
.append("rect") | |
.classed("bars",true) | |
.attr("x", function(d,i) { return 20 + (i * 40)}) | |
.attr("y", function(d,i) { return 300 - yScale(d.value);}) | |
.attr("width", 29) | |
.attr("height", function(d,i) { return yScale(d.value);}) | |
.style("fill","grey"); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment