Skip to content

Instantly share code, notes, and snippets.

@lucaguery
Created January 26, 2018 15:27
Show Gist options
  • Save lucaguery/14b8b9c0d0fc8e78ede5cdcbd6288fdf to your computer and use it in GitHub Desktop.
Save lucaguery/14b8b9c0d0fc8e78ede5cdcbd6288fdf to your computer and use it in GitHub Desktop.
transition
license: mit
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.axis text {
font: 10px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.x.axis path {
display: none;
}
</style>
<body>
<script src="//d3js.org/d3.v4.min.js"></script>
<script>
// Source: https://bl.ocks.org/mbostock/3887051
var n = 10, // number of samples
m = 5; // number of series
var data = d3.range(m).map(function() {
return d3.range(n).map(Math.random);
});
var margin = {top: 20, right: 30, bottom: 30, left: 40},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var y = d3.scaleLinear()
.domain([0, 1])
.range([height, 0]);
var x0 = d3.scaleBand()
.domain(d3.range(n))
.range([0, width], .2);
var x1 = d3.scaleBand()
.domain(d3.range(m))
.range([0, x0.bandwidth() - 10]);
var z = d3.scaleOrdinal()
.range(["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56", "#d0743c", "#ff8c00"]);
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
svg.append("g").selectAll("g")
.data(data)
.enter().append("g")
.style("fill", function(d, i) { return z(i); })
.attr("transform", function(d, i) { return "translate(" + x1(i) + ",0)"; })
.selectAll("rect")
.data(function(d) { return d; })
.enter().append("rect")
.attr("width", x1.bandwidth())
.attr("height", y)
.attr("x", function(d, i) { return x0(i); })
.attr("y", function(d) { return height - y(d); });
</script>
symbol date price
MSFT 01/01/2000 39.81
MSFT 01/02/2000 36.35
MSFT 01/03/2000 43.22
MSFT 01/04/2000 28.37
MSFT 01/05/2000 25.45
MSFT 01/06/2000 32.54
MSFT 01/07/2000 28.4
MSFT 01/08/2000 28.4
MSFT 01/09/2000 24.53
MSFT 01/10/2000 28.02
MSFT 01/11/2000 23.34
MSFT 01/12/2000 17.65
MSFT 01/01/2001 24.84
MSFT 01/02/2001 24
MSFT 01/03/2001 22.25
MSFT 01/04/2001 27.56
MSFT 01/05/2001 28.14
MSFT 01/06/2001 29.7
MSFT 01/07/2001 26.93
MSFT 01/08/2001 23.21
MSFT 01/09/2001 20.82
MSFT 01/10/2001 23.65
MSFT 01/11/2001 26.12
MSFT 01/12/2001 26.95
MSFT 01/01/2002 25.92
MSFT 01/02/2002 23.73
MSFT 01/03/2002 24.53
MSFT 01/04/2002 21.26
MSFT 01/05/2002 20.71
MSFT 01/06/2002 22.25
MSFT 01/07/2002 19.52
MSFT 01/08/2002 19.97
MSFT 01/09/2002 17.79
MSFT 01/10/2002 21.75
MSFT 01/11/2002 23.46
MSFT 01/12/2002 21.03
MSFT 01/01/2003 19.31
MSFT 01/02/2003 19.34
MSFT 01/03/2003 19.76
MSFT 01/04/2003 20.87
MSFT 01/05/2003 20.09
MSFT 01/06/2003 20.93
MSFT 01/07/2003 21.56
MSFT 01/08/2003 21.65
MSFT 01/09/2003 22.69
MSFT 01/10/2003 21.45
MSFT 01/11/2003 21.1
MSFT 01/12/2003 22.46
MSFT 01/01/2004 22.69
MSFT 01/02/2004 21.77
MSFT 01/03/2004 20.46
MSFT 01/04/2004 21.45
MSFT 01/05/2004 21.53
MSFT 01/06/2004 23.44
MSFT 01/07/2004 23.38
MSFT 01/08/2004 22.47
MSFT 01/09/2004 22.76
MSFT 01/10/2004 23.02
MSFT 01/11/2004 24.6
MSFT 01/12/2004 24.52
MSFT 01/01/2005 24.11
MSFT 01/02/2005 23.15
MSFT 01/03/2005 22.24
MSFT 01/04/2005 23.28
MSFT 01/05/2005 23.82
MSFT 01/06/2005 22.93
MSFT 01/07/2005 23.64
MSFT 01/08/2005 25.35
MSFT 01/09/2005 23.83
MSFT 01/10/2005 23.8
MSFT 01/11/2005 25.71
MSFT 01/12/2005 24.29
MSFT 01/01/2006 26.14
MSFT 01/02/2006 25.04
MSFT 01/03/2006 25.36
MSFT 01/04/2006 22.5
MSFT 01/05/2006 21.19
MSFT 01/06/2006 21.8
MSFT 01/07/2006 22.51
MSFT 01/08/2006 24.13
MSFT 01/09/2006 25.68
MSFT 01/10/2006 26.96
MSFT 01/11/2006 27.66
MSFT 01/12/2006 28.13
MSFT 01/01/2007 29.07
MSFT 01/02/2007 26.63
MSFT 01/03/2007 26.35
MSFT 01/04/2007 28.3
MSFT 01/05/2007 29.11
MSFT 01/06/2007 27.95
MSFT 01/07/2007 27.5
MSFT 01/08/2007 27.34
MSFT 01/09/2007 28.04
MSFT 01/10/2007 35.03
MSFT 01/11/2007 32.09
MSFT 01/12/2007 34
MSFT 01/01/2008 31.13
MSFT 01/02/2008 26.07
MSFT 01/03/2008 27.21
MSFT 01/04/2008 27.34
MSFT 01/05/2008 27.25
MSFT 01/06/2008 26.47
MSFT 01/07/2008 24.75
MSFT 01/08/2008 26.36
MSFT 01/09/2008 25.78
MSFT 01/10/2008 21.57
MSFT 01/11/2008 19.66
MSFT 01/12/2008 18.91
MSFT 01/01/2009 16.63
MSFT 01/02/2009 15.81
MSFT 01/03/2009 17.99
MSFT 01/04/2009 19.84
MSFT 01/05/2009 20.59
MSFT 01/06/2009 23.42
MSFT 01/07/2009 23.18
MSFT 01/08/2009 24.43
MSFT 01/09/2009 25.49
MSFT 01/10/2009 27.48
MSFT 01/11/2009 29.27
MSFT 01/12/2009 30.34
MSFT 01/01/2010 28.05
MSFT 01/02/2010 28.67
MSFT 01/03/2010 28.8
AMZN 01/01/2000 64.56
AMZN 01/02/2000 68.87
AMZN 01/03/2000 67
AMZN 01/04/2000 55.19
AMZN 01/05/2000 48.31
AMZN 01/06/2000 36.31
AMZN 01/07/2000 30.12
AMZN 01/08/2000 41.5
AMZN 01/09/2000 38.44
AMZN 01/10/2000 36.62
AMZN 01/11/2000 24.69
AMZN 01/12/2000 15.56
AMZN 01/01/2001 17.31
AMZN 01/02/2001 10.19
AMZN 01/03/2001 10.23
AMZN 01/04/2001 15.78
AMZN 01/05/2001 16.69
AMZN 01/06/2001 14.15
AMZN 01/07/2001 12.49
AMZN 01/08/2001 8.94
AMZN 01/09/2001 5.97
AMZN 01/10/2001 6.98
AMZN 01/11/2001 11.32
AMZN 01/12/2001 10.82
AMZN 01/01/2002 14.19
AMZN 01/02/2002 14.1
AMZN 01/03/2002 14.3
AMZN 01/04/2002 16.69
AMZN 01/05/2002 18.23
AMZN 01/06/2002 16.25
AMZN 01/07/2002 14.45
AMZN 01/08/2002 14.94
AMZN 01/09/2002 15.93
AMZN 01/10/2002 19.36
AMZN 01/11/2002 23.35
AMZN 01/12/2002 18.89
AMZN 01/01/2003 21.85
AMZN 01/02/2003 22.01
AMZN 01/03/2003 26.03
AMZN 01/04/2003 28.69
AMZN 01/05/2003 35.89
AMZN 01/06/2003 36.32
AMZN 01/07/2003 41.64
AMZN 01/08/2003 46.32
AMZN 01/09/2003 48.43
AMZN 01/10/2003 54.43
AMZN 01/11/2003 53.97
AMZN 01/12/2003 52.62
AMZN 01/01/2004 50.4
AMZN 01/02/2004 43.01
AMZN 01/03/2004 43.28
AMZN 01/04/2004 43.6
AMZN 01/05/2004 48.5
AMZN 01/06/2004 54.4
AMZN 01/07/2004 38.92
AMZN 01/08/2004 38.14
AMZN 01/09/2004 40.86
AMZN 01/10/2004 34.13
AMZN 01/11/2004 39.68
AMZN 01/12/2004 44.29
AMZN 01/01/2005 43.22
AMZN 01/02/2005 35.18
AMZN 01/03/2005 34.27
AMZN 01/04/2005 32.36
AMZN 01/05/2005 35.51
AMZN 01/06/2005 33.09
AMZN 01/07/2005 45.15
AMZN 01/08/2005 42.7
AMZN 01/09/2005 45.3
AMZN 01/10/2005 39.86
AMZN 01/11/2005 48.46
AMZN 01/12/2005 47.15
AMZN 01/01/2006 44.82
AMZN 01/02/2006 37.44
AMZN 01/03/2006 36.53
AMZN 01/04/2006 35.21
AMZN 01/05/2006 34.61
AMZN 01/06/2006 38.68
AMZN 01/07/2006 26.89
AMZN 01/08/2006 30.83
AMZN 01/09/2006 32.12
AMZN 01/10/2006 38.09
AMZN 01/11/2006 40.34
AMZN 01/12/2006 39.46
AMZN 01/01/2007 37.67
AMZN 01/02/2007 39.14
AMZN 01/03/2007 39.79
AMZN 01/04/2007 61.33
AMZN 01/05/2007 69.14
AMZN 01/06/2007 68.41
AMZN 01/07/2007 78.54
AMZN 01/08/2007 79.91
AMZN 01/09/2007 93.15
AMZN 01/10/2007 89.15
AMZN 01/11/2007 90.56
AMZN 01/12/2007 92.64
AMZN 01/01/2008 77.7
AMZN 01/02/2008 64.47
AMZN 01/03/2008 71.3
AMZN 01/04/2008 78.63
AMZN 01/05/2008 81.62
AMZN 01/06/2008 73.33
AMZN 01/07/2008 76.34
AMZN 01/08/2008 80.81
AMZN 01/09/2008 72.76
AMZN 01/10/2008 57.24
AMZN 01/11/2008 42.7
AMZN 01/12/2008 51.28
AMZN 01/01/2009 58.82
AMZN 01/02/2009 64.79
AMZN 01/03/2009 73.44
AMZN 01/04/2009 80.52
AMZN 01/05/2009 77.99
AMZN 01/06/2009 83.66
AMZN 01/07/2009 85.76
AMZN 01/08/2009 81.19
AMZN 01/09/2009 93.36
AMZN 01/10/2009 118.81
AMZN 01/11/2009 135.91
AMZN 01/12/2009 134.52
AMZN 01/01/2010 125.41
AMZN 01/02/2010 118.4
AMZN 01/03/2010 128.82
IBM 01/01/2000 100.52
IBM 01/02/2000 92.11
IBM 01/03/2000 106.11
IBM 01/04/2000 99.95
IBM 01/05/2000 96.31
IBM 01/06/2000 98.33
IBM 01/07/2000 100.74
IBM 01/08/2000 118.62
IBM 01/09/2000 101.19
IBM 01/10/2000 88.5
IBM 01/11/2000 84.12
IBM 01/12/2000 76.47
IBM 01/01/2001 100.76
IBM 01/02/2001 89.98
IBM 01/03/2001 86.63
IBM 01/04/2001 103.7
IBM 01/05/2001 100.82
IBM 01/06/2001 102.35
IBM 01/07/2001 94.87
IBM 01/08/2001 90.25
IBM 01/09/2001 82.82
IBM 01/10/2001 97.58
IBM 01/11/2001 104.5
IBM 01/12/2001 109.36
IBM 01/01/2002 97.54
IBM 01/02/2002 88.82
IBM 01/03/2002 94.15
IBM 01/04/2002 75.82
IBM 01/05/2002 72.97
IBM 01/06/2002 65.31
IBM 01/07/2002 63.86
IBM 01/08/2002 68.52
IBM 01/09/2002 53.01
IBM 01/10/2002 71.76
IBM 01/11/2002 79.16
IBM 01/12/2002 70.58
IBM 01/01/2003 71.22
IBM 01/02/2003 71.13
IBM 01/03/2003 71.57
IBM 01/04/2003 77.47
IBM 01/05/2003 80.48
IBM 01/06/2003 75.42
IBM 01/07/2003 74.28
IBM 01/08/2003 75.12
IBM 01/09/2003 80.91
IBM 01/10/2003 81.96
IBM 01/11/2003 83.08
IBM 01/12/2003 85.05
IBM 01/01/2004 91.06
IBM 01/02/2004 88.7
IBM 01/03/2004 84.41
IBM 01/04/2004 81.04
IBM 01/05/2004 81.59
IBM 01/06/2004 81.19
IBM 01/07/2004 80.19
IBM 01/08/2004 78.17
IBM 01/09/2004 79.13
IBM 01/10/2004 82.84
IBM 01/11/2004 87.15
IBM 01/12/2004 91.16
IBM 01/01/2005 86.39
IBM 01/02/2005 85.78
IBM 01/03/2005 84.66
IBM 01/04/2005 70.77
IBM 01/05/2005 70.18
IBM 01/06/2005 68.93
IBM 01/07/2005 77.53
IBM 01/08/2005 75.07
IBM 01/09/2005 74.7
IBM 01/10/2005 76.25
IBM 01/11/2005 82.98
IBM 01/12/2005 76.73
IBM 01/01/2006 75.89
IBM 01/02/2006 75.09
IBM 01/03/2006 77.17
IBM 01/04/2006 77.05
IBM 01/05/2006 75.04
IBM 01/06/2006 72.15
IBM 01/07/2006 72.7
IBM 01/08/2006 76.35
IBM 01/09/2006 77.26
IBM 01/10/2006 87.06
IBM 01/11/2006 86.95
IBM 01/12/2006 91.9
IBM 01/01/2007 93.79
IBM 01/02/2007 88.18
IBM 01/03/2007 89.44
IBM 01/04/2007 96.98
IBM 01/05/2007 101.54
IBM 01/06/2007 100.25
IBM 01/07/2007 105.4
IBM 01/08/2007 111.54
IBM 01/09/2007 112.6
IBM 01/10/2007 111
IBM 01/11/2007 100.9
IBM 01/12/2007 103.7
IBM 01/01/2008 102.75
IBM 01/02/2008 109.64
IBM 01/03/2008 110.87
IBM 01/04/2008 116.23
IBM 01/05/2008 125.14
IBM 01/06/2008 114.6
IBM 01/07/2008 123.74
IBM 01/08/2008 118.16
IBM 01/09/2008 113.53
IBM 01/10/2008 90.24
IBM 01/11/2008 79.65
IBM 01/12/2008 82.15
IBM 01/01/2009 89.46
IBM 01/02/2009 90.32
IBM 01/03/2009 95.09
IBM 01/04/2009 101.29
IBM 01/05/2009 104.85
IBM 01/06/2009 103.01
IBM 01/07/2009 116.34
IBM 01/08/2009 117
IBM 01/09/2009 118.55
IBM 01/10/2009 119.54
IBM 01/11/2009 125.79
IBM 01/12/2009 130.32
IBM 01/01/2010 121.85
IBM 01/02/2010 127.16
IBM 01/03/2010 125.55
AAPL 01/01/2000 25.94
AAPL 01/02/2000 28.66
AAPL 01/03/2000 33.95
AAPL 01/04/2000 31.01
AAPL 01/05/2000 21
AAPL 01/06/2000 26.19
AAPL 01/07/2000 25.41
AAPL 01/08/2000 30.47
AAPL 01/09/2000 12.88
AAPL 01/10/2000 9.78
AAPL 01/11/2000 8.25
AAPL 01/12/2000 7.44
AAPL 01/01/2001 10.81
AAPL 01/02/2001 9.12
AAPL 01/03/2001 11.03
AAPL 01/04/2001 12.74
AAPL 01/05/2001 9.98
AAPL 01/06/2001 11.62
AAPL 01/07/2001 9.4
AAPL 01/08/2001 9.27
AAPL 01/09/2001 7.76
AAPL 01/10/2001 8.78
AAPL 01/11/2001 10.65
AAPL 01/12/2001 10.95
AAPL 01/01/2002 12.36
AAPL 01/02/2002 10.85
AAPL 01/03/2002 11.84
AAPL 01/04/2002 12.14
AAPL 01/05/2002 11.65
AAPL 01/06/2002 8.86
AAPL 01/07/2002 7.63
AAPL 01/08/2002 7.38
AAPL 01/09/2002 7.25
AAPL 01/10/2002 8.03
AAPL 01/11/2002 7.75
AAPL 01/12/2002 7.16
AAPL 01/01/2003 7.18
AAPL 01/02/2003 7.51
AAPL 01/03/2003 7.07
AAPL 01/04/2003 7.11
AAPL 01/05/2003 8.98
AAPL 01/06/2003 9.53
AAPL 01/07/2003 10.54
AAPL 01/08/2003 11.31
AAPL 01/09/2003 10.36
AAPL 01/10/2003 11.44
AAPL 01/11/2003 10.45
AAPL 01/12/2003 10.69
AAPL 01/01/2004 11.28
AAPL 01/02/2004 11.96
AAPL 01/03/2004 13.52
AAPL 01/04/2004 12.89
AAPL 01/05/2004 14.03
AAPL 01/06/2004 16.27
AAPL 01/07/2004 16.17
AAPL 01/08/2004 17.25
AAPL 01/09/2004 19.38
AAPL 01/10/2004 26.2
AAPL 01/11/2004 33.53
AAPL 01/12/2004 32.2
AAPL 01/01/2005 38.45
AAPL 01/02/2005 44.86
AAPL 01/03/2005 41.67
AAPL 01/04/2005 36.06
AAPL 01/05/2005 39.76
AAPL 01/06/2005 36.81
AAPL 01/07/2005 42.65
AAPL 01/08/2005 46.89
AAPL 01/09/2005 53.61
AAPL 01/10/2005 57.59
AAPL 01/11/2005 67.82
AAPL 01/12/2005 71.89
AAPL 01/01/2006 75.51
AAPL 01/02/2006 68.49
AAPL 01/03/2006 62.72
AAPL 01/04/2006 70.39
AAPL 01/05/2006 59.77
AAPL 01/06/2006 57.27
AAPL 01/07/2006 67.96
AAPL 01/08/2006 67.85
AAPL 01/09/2006 76.98
AAPL 01/10/2006 81.08
AAPL 01/11/2006 91.66
AAPL 01/12/2006 84.84
AAPL 01/01/2007 85.73
AAPL 01/02/2007 84.61
AAPL 01/03/2007 92.91
AAPL 01/04/2007 99.8
AAPL 01/05/2007 121.19
AAPL 01/06/2007 122.04
AAPL 01/07/2007 131.76
AAPL 01/08/2007 138.48
AAPL 01/09/2007 153.47
AAPL 01/10/2007 189.95
AAPL 01/11/2007 182.22
AAPL 01/12/2007 198.08
AAPL 01/01/2008 135.36
AAPL 01/02/2008 125.02
AAPL 01/03/2008 143.5
AAPL 01/04/2008 173.95
AAPL 01/05/2008 188.75
AAPL 01/06/2008 167.44
AAPL 01/07/2008 158.95
AAPL 01/08/2008 169.53
AAPL 01/09/2008 113.66
AAPL 01/10/2008 107.59
AAPL 01/11/2008 92.67
AAPL 01/12/2008 85.35
AAPL 01/01/2009 90.13
AAPL 01/02/2009 89.31
AAPL 01/03/2009 105.12
AAPL 01/04/2009 125.83
AAPL 01/05/2009 135.81
AAPL 01/06/2009 142.43
AAPL 01/07/2009 163.39
AAPL 01/08/2009 168.21
AAPL 01/09/2009 185.35
AAPL 01/10/2009 188.5
AAPL 01/11/2009 199.91
AAPL 01/12/2009 210.73
AAPL 01/01/2010 192.06
AAPL 01/02/2010 204.62
AAPL 01/03/2010 223.02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment