Built with blockbuilder.org
Created
June 15, 2019 20:21
-
-
Save monaddle/f607951f591435d9ea697b680f9e130f to your computer and use it in GitHub Desktop.
fresh block
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
license: mit |
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> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<style> | |
.axis path, | |
.axis line { | |
fill: none; | |
stroke: #000; | |
shape-rendering: crispEdges; | |
} | |
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
</style> | |
</head> | |
<body> | |
<script> | |
// Feel free to change or delete any of the code you see in this editor! | |
var dates = [new Date("2007-01-01"), new Date("2007-01-02"), new Date("2007-01-05")]; | |
var events = [ | |
{ | |
'date': (new Date("2007-01-01")), | |
'text': 'This little piggy went to market' | |
}, | |
{ | |
'date': new Date("2007-02-04"), | |
'text': 'This little piggy stayed home' | |
}, | |
{ | |
'date': new Date('2007-04-05'), | |
'text': 'This little piggy went to Chile' | |
}] | |
var data = [1, 2, 3, 5, 8, 13]; | |
var svg = d3.select("body").append("svg") | |
.attr("width", 500) | |
.attr("height", 500); | |
var x = d3.scaleTime(events) | |
.range([0, 480]) | |
.domain(d3.extent(events, function(d){return d.date})) | |
.nice(); | |
svg.selectAll('.dot') | |
.data(events).enter() | |
.append('circle') | |
.attr('class', 'dot') | |
.attr("r", 3.5) | |
.attr('cx', function(d){return x(d.date)}) | |
.attr('cy', 400) | |
svg.selectAll('.text') | |
.data(events).enter() | |
.append('text') | |
.text(function(d) { return d.text}) | |
.attr('x', function(d){return x(d.date)}) | |
.attr('y', 350); | |
var xAxis = d3 | |
.axisBottom() | |
.scale(x) | |
svg.append("g") | |
.attr("class", "x axis") | |
.attr("transform", "translate(0,480)") | |
.call(xAxis) | |
.append("text") | |
.attr("class", "label") | |
.attr("x", 450) | |
.attr("y", -6) | |
.style("text-anchor", "end") | |
.text("Sepal Width (cm)"); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment