Built with blockbuilder.org
Created
July 26, 2018 03:41
-
-
Save curiousYi/479890e61da18133e9c12d4cb8b240bf to your computer and use it in GitHub Desktop.
fresh block
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://d3js.org/d3.v4.min.js"></script> | |
<style> | |
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
svg { | |
height: 100%; | |
width: 100%; | |
} | |
</style> | |
</head> | |
<body> | |
<svg></svg> | |
<script> | |
// Feel free to change or delete any of the code you see in this editor! | |
/* | |
date New York San Francisco Austin | |
20111001 63.4 62.7 72.2 | |
20111002 58.0 59.9 67.7 | |
20111003 53.3 59.1 69.4 | |
20111004 55.7 58.8 68.0 | |
*/ | |
//TO-DO need some way to parse the .tsv file | |
var rectWidth = 100; | |
var height = 300; | |
var data = [63.4, 58.0, 53.3, 55.7]; | |
var myXAxis = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] | |
var svg = d3.select('svg'); | |
svg.selectAll() | |
.data(data) | |
.enter().append('rect') | |
.attr('x', (d, i) => i * rectWidth) | |
.attr('y', d => height - d) | |
.attr('width', rectWidth) | |
.attr('height', d => height-d) | |
.attr('fill', 'blue') | |
.attr('stroke', '#fff') | |
.attr('transform', 'translate(20,20)'); | |
var extent = d3.extent(data, d=> d), | |
yScale = d3.scaleLinear() | |
.domain(extent) | |
.range([height, 0]); | |
var yAxis = d3.axisLeft() | |
.scale(yScale); | |
svg.append('g') | |
.attr('transform', 'translate(20, 20)') | |
.call(yAxis); | |
var linearScale = d3.scaleLinear() | |
.domain([0, 11]) | |
.range([0, 600]); | |
svg.selectAll('text') | |
.data(myXAxis) | |
.enter() | |
.append('text') | |
.attr('x', function(d, i) { | |
return linearScale(i); | |
}) | |
.text(function(d) { | |
return d; | |
}) | |
.attr("transform", "translate(100,500)"); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment