Skip to content

Instantly share code, notes, and snippets.

@curran
Last active January 30, 2017 17:06
Show Gist options
  • Save curran/02163a13a40112e0ab6f14bbacc986f8 to your computer and use it in GitHub Desktop.
Save curran/02163a13a40112e0ab6f14bbacc986f8 to your computer and use it in GitHub Desktop.
Small Multiples with Reusable Charts
license: mit

This example is a small multiples experiment based on code written by Mike Bostock in 2012 as part of his tutorial Towards Reusable Charts.

I had heard that the "Towards Reusable Charts" style can be used to easily create small multiples, but I didn't quite grok how. This example shows one way that it can work, drawing data and inspiration from this other example Small Multiples III. On the way, I upgraded the original reusable line chart code to D3 v4, with minimal modifications. I also wanted to add a title to each instance of the chart, so ended up adding the values and title accessors to make it work well with the output from d3.nest.

forked from curran's block: Towards Reusable Charts Example

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Reusable Chart Example</title>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="time-series-chart.js"></script>
<style>
.axis text {
font: 10px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000000;
shape-rendering: crispEdges;
}
.line {
fill: none;
stroke: #707070;
}
.area {
fill: #c6c6c6;
}
</style>
</head>
<body>
<p id="example">
<script>
var parseDate = d3.timeParse("%b %Y");
var chart = timeSeriesChart()
.x(function(d) { return parseDate(d.date); })
.y(function(d) { return +d.price; })
.width(950)
.height(60)
.values(function (d){ return d.values; })
.title(function (d){ return d.key; })
.margin({top: 20, right: 20, bottom: 20, left: 134});
d3.tsv("stocks.tsv", function(error, data) {
if (error) throw error;
// Use a global extent (so GOOG's axis is aligned with the others).
chart.xExtent(d3.extent(data, chart.x()));
var symbols = d3.nest()
.key(function(d) { return d.symbol; })
.entries(data);
d3.select("body")
.selectAll(".chart")
.data(symbols)
.enter()
.append("div")
.attr("class", "chart")
.call(chart);
});
</script>
</body>
</html>
symbol date price
S&P 500 Jan 2000 1394.46
S&P 500 Feb 2000 1366.42
S&P 500 Mar 2000 1498.58
S&P 500 Apr 2000 1452.43
S&P 500 May 2000 1420.6
S&P 500 Jun 2000 1454.6
S&P 500 Jul 2000 1430.83
S&P 500 Aug 2000 1517.68
S&P 500 Sep 2000 1436.51
S&P 500 Oct 2000 1429.4
S&P 500 Nov 2000 1314.95
S&P 500 Dec 2000 1320.28
S&P 500 Jan 2001 1366.01
S&P 500 Feb 2001 1239.94
S&P 500 Mar 2001 1160.33
S&P 500 Apr 2001 1249.46
S&P 500 May 2001 1255.82
S&P 500 Jun 2001 1224.38
S&P 500 Jul 2001 1211.23
S&P 500 Aug 2001 1133.58
S&P 500 Sep 2001 1040.94
S&P 500 Oct 2001 1059.78
S&P 500 Nov 2001 1139.45
S&P 500 Dec 2001 1148.08
S&P 500 Jan 2002 1130.2
S&P 500 Feb 2002 1106.73
S&P 500 Mar 2002 1147.39
S&P 500 Apr 2002 1076.92
S&P 500 May 2002 1067.14
S&P 500 Jun 2002 989.82
S&P 500 Jul 2002 911.62
S&P 500 Aug 2002 916.07
S&P 500 Sep 2002 815.28
S&P 500 Oct 2002 885.76
S&P 500 Nov 2002 936.31
S&P 500 Dec 2002 879.82
S&P 500 Jan 2003 855.7
S&P 500 Feb 2003 841.15
S&P 500 Mar 2003 848.18
S&P 500 Apr 2003 916.92
S&P 500 May 2003 963.59
S&P 500 Jun 2003 974.5
S&P 500 Jul 2003 990.31
S&P 500 Aug 2003 1008.01
S&P 500 Sep 2003 995.97
S&P 500 Oct 2003 1050.71
S&P 500 Nov 2003 1058.2
S&P 500 Dec 2003 1111.92
S&P 500 Jan 2004 1131.13
S&P 500 Feb 2004 1144.94
S&P 500 Mar 2004 1126.21
S&P 500 Apr 2004 1107.3
S&P 500 May 2004 1120.68
S&P 500 Jun 2004 1140.84
S&P 500 Jul 2004 1101.72
S&P 500 Aug 2004 1104.24
S&P 500 Sep 2004 1114.58
S&P 500 Oct 2004 1130.2
S&P 500 Nov 2004 1173.82
S&P 500 Dec 2004 1211.92
S&P 500 Jan 2005 1181.27
S&P 500 Feb 2005 1203.6
S&P 500 Mar 2005 1180.59
S&P 500 Apr 2005 1156.85
S&P 500 May 2005 1191.5
S&P 500 Jun 2005 1191.33
S&P 500 Jul 2005 1234.18
S&P 500 Aug 2005 1220.33
S&P 500 Sep 2005 1228.81
S&P 500 Oct 2005 1207.01
S&P 500 Nov 2005 1249.48
S&P 500 Dec 2005 1248.29
S&P 500 Jan 2006 1280.08
S&P 500 Feb 2006 1280.66
S&P 500 Mar 2006 1294.87
S&P 500 Apr 2006 1310.61
S&P 500 May 2006 1270.09
S&P 500 Jun 2006 1270.2
S&P 500 Jul 2006 1276.66
S&P 500 Aug 2006 1303.82
S&P 500 Sep 2006 1335.85
S&P 500 Oct 2006 1377.94
S&P 500 Nov 2006 1400.63
S&P 500 Dec 2006 1418.3
S&P 500 Jan 2007 1438.24
S&P 500 Feb 2007 1406.82
S&P 500 Mar 2007 1420.86
S&P 500 Apr 2007 1482.37
S&P 500 May 2007 1530.62
S&P 500 Jun 2007 1503.35
S&P 500 Jul 2007 1455.27
S&P 500 Aug 2007 1473.99
S&P 500 Sep 2007 1526.75
S&P 500 Oct 2007 1549.38
S&P 500 Nov 2007 1481.14
S&P 500 Dec 2007 1468.36
S&P 500 Jan 2008 1378.55
S&P 500 Feb 2008 1330.63
S&P 500 Mar 2008 1322.7
S&P 500 Apr 2008 1385.59
S&P 500 May 2008 1400.38
S&P 500 Jun 2008 1280
S&P 500 Jul 2008 1267.38
S&P 500 Aug 2008 1282.83
S&P 500 Sep 2008 1166.36
S&P 500 Oct 2008 968.75
S&P 500 Nov 2008 896.24
S&P 500 Dec 2008 903.25
S&P 500 Jan 2009 825.88
S&P 500 Feb 2009 735.09
S&P 500 Mar 2009 797.87
S&P 500 Apr 2009 872.81
S&P 500 May 2009 919.14
S&P 500 Jun 2009 919.32
S&P 500 Jul 2009 987.48
S&P 500 Aug 2009 1020.62
S&P 500 Sep 2009 1057.08
S&P 500 Oct 2009 1036.19
S&P 500 Nov 2009 1095.63
S&P 500 Dec 2009 1115.1
S&P 500 Jan 2010 1073.87
S&P 500 Feb 2010 1104.49
S&P 500 Mar 2010 1140.45
MSFT Jan 2000 39.81
MSFT Feb 2000 36.35
MSFT Mar 2000 43.22
MSFT Apr 2000 28.37
MSFT May 2000 25.45
MSFT Jun 2000 32.54
MSFT Jul 2000 28.4
MSFT Aug 2000 28.4
MSFT Sep 2000 24.53
MSFT Oct 2000 28.02
MSFT Nov 2000 23.34
MSFT Dec 2000 17.65
MSFT Jan 2001 24.84
MSFT Feb 2001 24
MSFT Mar 2001 22.25
MSFT Apr 2001 27.56
MSFT May 2001 28.14
MSFT Jun 2001 29.7
MSFT Jul 2001 26.93
MSFT Aug 2001 23.21
MSFT Sep 2001 20.82
MSFT Oct 2001 23.65
MSFT Nov 2001 26.12
MSFT Dec 2001 26.95
MSFT Jan 2002 25.92
MSFT Feb 2002 23.73
MSFT Mar 2002 24.53
MSFT Apr 2002 21.26
MSFT May 2002 20.71
MSFT Jun 2002 22.25
MSFT Jul 2002 19.52
MSFT Aug 2002 19.97
MSFT Sep 2002 17.79
MSFT Oct 2002 21.75
MSFT Nov 2002 23.46
MSFT Dec 2002 21.03
MSFT Jan 2003 19.31
MSFT Feb 2003 19.34
MSFT Mar 2003 19.76
MSFT Apr 2003 20.87
MSFT May 2003 20.09
MSFT Jun 2003 20.93
MSFT Jul 2003 21.56
MSFT Aug 2003 21.65
MSFT Sep 2003 22.69
MSFT Oct 2003 21.45
MSFT Nov 2003 21.1
MSFT Dec 2003 22.46
MSFT Jan 2004 22.69
MSFT Feb 2004 21.77
MSFT Mar 2004 20.46
MSFT Apr 2004 21.45
MSFT May 2004 21.53
MSFT Jun 2004 23.44
MSFT Jul 2004 23.38
MSFT Aug 2004 22.47
MSFT Sep 2004 22.76
MSFT Oct 2004 23.02
MSFT Nov 2004 24.6
MSFT Dec 2004 24.52
MSFT Jan 2005 24.11
MSFT Feb 2005 23.15
MSFT Mar 2005 22.24
MSFT Apr 2005 23.28
MSFT May 2005 23.82
MSFT Jun 2005 22.93
MSFT Jul 2005 23.64
MSFT Aug 2005 25.35
MSFT Sep 2005 23.83
MSFT Oct 2005 23.8
MSFT Nov 2005 25.71
MSFT Dec 2005 24.29
MSFT Jan 2006 26.14
MSFT Feb 2006 25.04
MSFT Mar 2006 25.36
MSFT Apr 2006 22.5
MSFT May 2006 21.19
MSFT Jun 2006 21.8
MSFT Jul 2006 22.51
MSFT Aug 2006 24.13
MSFT Sep 2006 25.68
MSFT Oct 2006 26.96
MSFT Nov 2006 27.66
MSFT Dec 2006 28.13
MSFT Jan 2007 29.07
MSFT Feb 2007 26.63
MSFT Mar 2007 26.35
MSFT Apr 2007 28.3
MSFT May 2007 29.11
MSFT Jun 2007 27.95
MSFT Jul 2007 27.5
MSFT Aug 2007 27.34
MSFT Sep 2007 28.04
MSFT Oct 2007 35.03
MSFT Nov 2007 32.09
MSFT Dec 2007 34
MSFT Jan 2008 31.13
MSFT Feb 2008 26.07
MSFT Mar 2008 27.21
MSFT Apr 2008 27.34
MSFT May 2008 27.25
MSFT Jun 2008 26.47
MSFT Jul 2008 24.75
MSFT Aug 2008 26.36
MSFT Sep 2008 25.78
MSFT Oct 2008 21.57
MSFT Nov 2008 19.66
MSFT Dec 2008 18.91
MSFT Jan 2009 16.63
MSFT Feb 2009 15.81
MSFT Mar 2009 17.99
MSFT Apr 2009 19.84
MSFT May 2009 20.59
MSFT Jun 2009 23.42
MSFT Jul 2009 23.18
MSFT Aug 2009 24.43
MSFT Sep 2009 25.49
MSFT Oct 2009 27.48
MSFT Nov 2009 29.27
MSFT Dec 2009 30.34
MSFT Jan 2010 28.05
MSFT Feb 2010 28.67
MSFT Mar 2010 28.8
AMZN Jan 2000 64.56
AMZN Feb 2000 68.87
AMZN Mar 2000 67
AMZN Apr 2000 55.19
AMZN May 2000 48.31
AMZN Jun 2000 36.31
AMZN Jul 2000 30.12
AMZN Aug 2000 41.5
AMZN Sep 2000 38.44
AMZN Oct 2000 36.62
AMZN Nov 2000 24.69
AMZN Dec 2000 15.56
AMZN Jan 2001 17.31
AMZN Feb 2001 10.19
AMZN Mar 2001 10.23
AMZN Apr 2001 15.78
AMZN May 2001 16.69
AMZN Jun 2001 14.15
AMZN Jul 2001 12.49
AMZN Aug 2001 8.94
AMZN Sep 2001 5.97
AMZN Oct 2001 6.98
AMZN Nov 2001 11.32
AMZN Dec 2001 10.82
AMZN Jan 2002 14.19
AMZN Feb 2002 14.1
AMZN Mar 2002 14.3
AMZN Apr 2002 16.69
AMZN May 2002 18.23
AMZN Jun 2002 16.25
AMZN Jul 2002 14.45
AMZN Aug 2002 14.94
AMZN Sep 2002 15.93
AMZN Oct 2002 19.36
AMZN Nov 2002 23.35
AMZN Dec 2002 18.89
AMZN Jan 2003 21.85
AMZN Feb 2003 22.01
AMZN Mar 2003 26.03
AMZN Apr 2003 28.69
AMZN May 2003 35.89
AMZN Jun 2003 36.32
AMZN Jul 2003 41.64
AMZN Aug 2003 46.32
AMZN Sep 2003 48.43
AMZN Oct 2003 54.43
AMZN Nov 2003 53.97
AMZN Dec 2003 52.62
AMZN Jan 2004 50.4
AMZN Feb 2004 43.01
AMZN Mar 2004 43.28
AMZN Apr 2004 43.6
AMZN May 2004 48.5
AMZN Jun 2004 54.4
AMZN Jul 2004 38.92
AMZN Aug 2004 38.14
AMZN Sep 2004 40.86
AMZN Oct 2004 34.13
AMZN Nov 2004 39.68
AMZN Dec 2004 44.29
AMZN Jan 2005 43.22
AMZN Feb 2005 35.18
AMZN Mar 2005 34.27
AMZN Apr 2005 32.36
AMZN May 2005 35.51
AMZN Jun 2005 33.09
AMZN Jul 2005 45.15
AMZN Aug 2005 42.7
AMZN Sep 2005 45.3
AMZN Oct 2005 39.86
AMZN Nov 2005 48.46
AMZN Dec 2005 47.15
AMZN Jan 2006 44.82
AMZN Feb 2006 37.44
AMZN Mar 2006 36.53
AMZN Apr 2006 35.21
AMZN May 2006 34.61
AMZN Jun 2006 38.68
AMZN Jul 2006 26.89
AMZN Aug 2006 30.83
AMZN Sep 2006 32.12
AMZN Oct 2006 38.09
AMZN Nov 2006 40.34
AMZN Dec 2006 39.46
AMZN Jan 2007 37.67
AMZN Feb 2007 39.14
AMZN Mar 2007 39.79
AMZN Apr 2007 61.33
AMZN May 2007 69.14
AMZN Jun 2007 68.41
AMZN Jul 2007 78.54
AMZN Aug 2007 79.91
AMZN Sep 2007 93.15
AMZN Oct 2007 89.15
AMZN Nov 2007 90.56
AMZN Dec 2007 92.64
AMZN Jan 2008 77.7
AMZN Feb 2008 64.47
AMZN Mar 2008 71.3
AMZN Apr 2008 78.63
AMZN May 2008 81.62
AMZN Jun 2008 73.33
AMZN Jul 2008 76.34
AMZN Aug 2008 80.81
AMZN Sep 2008 72.76
AMZN Oct 2008 57.24
AMZN Nov 2008 42.7
AMZN Dec 2008 51.28
AMZN Jan 2009 58.82
AMZN Feb 2009 64.79
AMZN Mar 2009 73.44
AMZN Apr 2009 80.52
AMZN May 2009 77.99
AMZN Jun 2009 83.66
AMZN Jul 2009 85.76
AMZN Aug 2009 81.19
AMZN Sep 2009 93.36
AMZN Oct 2009 118.81
AMZN Nov 2009 135.91
AMZN Dec 2009 134.52
AMZN Jan 2010 125.41
AMZN Feb 2010 118.4
AMZN Mar 2010 128.82
IBM Jan 2000 100.52
IBM Feb 2000 92.11
IBM Mar 2000 106.11
IBM Apr 2000 99.95
IBM May 2000 96.31
IBM Jun 2000 98.33
IBM Jul 2000 100.74
IBM Aug 2000 118.62
IBM Sep 2000 101.19
IBM Oct 2000 88.5
IBM Nov 2000 84.12
IBM Dec 2000 76.47
IBM Jan 2001 100.76
IBM Feb 2001 89.98
IBM Mar 2001 86.63
IBM Apr 2001 103.7
IBM May 2001 100.82
IBM Jun 2001 102.35
IBM Jul 2001 94.87
IBM Aug 2001 90.25
IBM Sep 2001 82.82
IBM Oct 2001 97.58
IBM Nov 2001 104.5
IBM Dec 2001 109.36
IBM Jan 2002 97.54
IBM Feb 2002 88.82
IBM Mar 2002 94.15
IBM Apr 2002 75.82
IBM May 2002 72.97
IBM Jun 2002 65.31
IBM Jul 2002 63.86
IBM Aug 2002 68.52
IBM Sep 2002 53.01
IBM Oct 2002 71.76
IBM Nov 2002 79.16
IBM Dec 2002 70.58
IBM Jan 2003 71.22
IBM Feb 2003 71.13
IBM Mar 2003 71.57
IBM Apr 2003 77.47
IBM May 2003 80.48
IBM Jun 2003 75.42
IBM Jul 2003 74.28
IBM Aug 2003 75.12
IBM Sep 2003 80.91
IBM Oct 2003 81.96
IBM Nov 2003 83.08
IBM Dec 2003 85.05
IBM Jan 2004 91.06
IBM Feb 2004 88.7
IBM Mar 2004 84.41
IBM Apr 2004 81.04
IBM May 2004 81.59
IBM Jun 2004 81.19
IBM Jul 2004 80.19
IBM Aug 2004 78.17
IBM Sep 2004 79.13
IBM Oct 2004 82.84
IBM Nov 2004 87.15
IBM Dec 2004 91.16
IBM Jan 2005 86.39
IBM Feb 2005 85.78
IBM Mar 2005 84.66
IBM Apr 2005 70.77
IBM May 2005 70.18
IBM Jun 2005 68.93
IBM Jul 2005 77.53
IBM Aug 2005 75.07
IBM Sep 2005 74.7
IBM Oct 2005 76.25
IBM Nov 2005 82.98
IBM Dec 2005 76.73
IBM Jan 2006 75.89
IBM Feb 2006 75.09
IBM Mar 2006 77.17
IBM Apr 2006 77.05
IBM May 2006 75.04
IBM Jun 2006 72.15
IBM Jul 2006 72.7
IBM Aug 2006 76.35
IBM Sep 2006 77.26
IBM Oct 2006 87.06
IBM Nov 2006 86.95
IBM Dec 2006 91.9
IBM Jan 2007 93.79
IBM Feb 2007 88.18
IBM Mar 2007 89.44
IBM Apr 2007 96.98
IBM May 2007 101.54
IBM Jun 2007 100.25
IBM Jul 2007 105.4
IBM Aug 2007 111.54
IBM Sep 2007 112.6
IBM Oct 2007 111
IBM Nov 2007 100.9
IBM Dec 2007 103.7
IBM Jan 2008 102.75
IBM Feb 2008 109.64
IBM Mar 2008 110.87
IBM Apr 2008 116.23
IBM May 2008 125.14
IBM Jun 2008 114.6
IBM Jul 2008 123.74
IBM Aug 2008 118.16
IBM Sep 2008 113.53
IBM Oct 2008 90.24
IBM Nov 2008 79.65
IBM Dec 2008 82.15
IBM Jan 2009 89.46
IBM Feb 2009 90.32
IBM Mar 2009 95.09
IBM Apr 2009 101.29
IBM May 2009 104.85
IBM Jun 2009 103.01
IBM Jul 2009 116.34
IBM Aug 2009 117
IBM Sep 2009 118.55
IBM Oct 2009 119.54
IBM Nov 2009 125.79
IBM Dec 2009 130.32
IBM Jan 2010 121.85
IBM Feb 2010 127.16
IBM Mar 2010 125.55
GOOG Aug 2004 102.37
GOOG Sep 2004 129.6
GOOG Oct 2004 190.64
GOOG Nov 2004 181.98
GOOG Dec 2004 192.79
GOOG Jan 2005 195.62
GOOG Feb 2005 187.99
GOOG Mar 2005 180.51
GOOG Apr 2005 220
GOOG May 2005 277.27
GOOG Jun 2005 294.15
GOOG Jul 2005 287.76
GOOG Aug 2005 286
GOOG Sep 2005 316.46
GOOG Oct 2005 372.14
GOOG Nov 2005 404.91
GOOG Dec 2005 414.86
GOOG Jan 2006 432.66
GOOG Feb 2006 362.62
GOOG Mar 2006 390
GOOG Apr 2006 417.94
GOOG May 2006 371.82
GOOG Jun 2006 419.33
GOOG Jul 2006 386.6
GOOG Aug 2006 378.53
GOOG Sep 2006 401.9
GOOG Oct 2006 476.39
GOOG Nov 2006 484.81
GOOG Dec 2006 460.48
GOOG Jan 2007 501.5
GOOG Feb 2007 449.45
GOOG Mar 2007 458.16
GOOG Apr 2007 471.38
GOOG May 2007 497.91
GOOG Jun 2007 522.7
GOOG Jul 2007 510
GOOG Aug 2007 515.25
GOOG Sep 2007 567.27
GOOG Oct 2007 707
GOOG Nov 2007 693
GOOG Dec 2007 691.48
GOOG Jan 2008 564.3
GOOG Feb 2008 471.18
GOOG Mar 2008 440.47
GOOG Apr 2008 574.29
GOOG May 2008 585.8
GOOG Jun 2008 526.42
GOOG Jul 2008 473.75
GOOG Aug 2008 463.29
GOOG Sep 2008 400.52
GOOG Oct 2008 359.36
GOOG Nov 2008 292.96
GOOG Dec 2008 307.65
GOOG Jan 2009 338.53
GOOG Feb 2009 337.99
GOOG Mar 2009 348.06
GOOG Apr 2009 395.97
GOOG May 2009 417.23
GOOG Jun 2009 421.59
GOOG Jul 2009 443.05
GOOG Aug 2009 461.67
GOOG Sep 2009 495.85
GOOG Oct 2009 536.12
GOOG Nov 2009 583
GOOG Dec 2009 619.98
GOOG Jan 2010 529.94
GOOG Feb 2010 526.8
GOOG Mar 2010 560.19
10 Year T-Note Jan 2000 6.67
10 Year T-Note Feb 2000 6.41
10 Year T-Note Mar 2000 6.02
10 Year T-Note Apr 2000 6.21
10 Year T-Note May 2000 6.28
10 Year T-Note Jun 2000 6.02
10 Year T-Note Jul 2000 6.03
10 Year T-Note Aug 2000 5.73
10 Year T-Note Sep 2000 5.78
10 Year T-Note Oct 2000 5.76
10 Year T-Note Nov 2000 5.44
10 Year T-Note Dec 2000 5.11
10 Year T-Note Jan 2001 5.18
10 Year T-Note Feb 2001 4.91
10 Year T-Note Mar 2001 4.91
10 Year T-Note Apr 2001 5.34
10 Year T-Note May 2001 5.41
10 Year T-Note Jun 2001 5.39
10 Year T-Note Jul 2001 5.04
10 Year T-Note Aug 2001 4.82
10 Year T-Note Sep 2001 4.57
10 Year T-Note Oct 2001 4.26
10 Year T-Note Nov 2001 4.74
10 Year T-Note Dec 2001 5.03
10 Year T-Note Jan 2002 5.03
10 Year T-Note Feb 2002 4.86
10 Year T-Note Mar 2002 5.41
10 Year T-Note Apr 2002 5.09
10 Year T-Note May 2002 5.04
10 Year T-Note Jun 2002 4.82
10 Year T-Note Jul 2002 4.47
10 Year T-Note Aug 2002 4.14
10 Year T-Note Sep 2002 3.61
10 Year T-Note Oct 2002 3.91
10 Year T-Note Nov 2002 4.21
10 Year T-Note Dec 2002 3.82
10 Year T-Note Jan 2003 3.97
10 Year T-Note Feb 2003 3.7
10 Year T-Note Mar 2003 3.82
10 Year T-Note Apr 2003 3.86
10 Year T-Note May 2003 3.35
10 Year T-Note Jun 2003 3.53
10 Year T-Note Jul 2003 4.47
10 Year T-Note Aug 2003 4.45
10 Year T-Note Sep 2003 3.94
10 Year T-Note Oct 2003 4.3
10 Year T-Note Nov 2003 4.32
10 Year T-Note Dec 2003 4.26
10 Year T-Note Jan 2004 4.14
10 Year T-Note Feb 2004 3.98
10 Year T-Note Mar 2004 3.84
10 Year T-Note Apr 2004 4.5
10 Year T-Note May 2004 4.66
10 Year T-Note Jun 2004 4.62
10 Year T-Note Jul 2004 4.47
10 Year T-Note Aug 2004 4.13
10 Year T-Note Sep 2004 4.12
10 Year T-Note Oct 2004 4.03
10 Year T-Note Nov 2004 4.36
10 Year T-Note Dec 2004 4.22
10 Year T-Note Jan 2005 4.13
10 Year T-Note Feb 2005 4.36
10 Year T-Note Mar 2005 4.5
10 Year T-Note Apr 2005 4.2
10 Year T-Note May 2005 4.01
10 Year T-Note Jun 2005 3.94
10 Year T-Note Jul 2005 4.29
10 Year T-Note Aug 2005 4.02
10 Year T-Note Sep 2005 4.33
10 Year T-Note Oct 2005 4.56
10 Year T-Note Nov 2005 4.5
10 Year T-Note Dec 2005 4.39
10 Year T-Note Jan 2006 4.53
10 Year T-Note Feb 2006 4.55
10 Year T-Note Mar 2006 4.85
10 Year T-Note Apr 2006 5.07
10 Year T-Note May 2006 5.11
10 Year T-Note Jun 2006 5.14
10 Year T-Note Jul 2006 4.99
10 Year T-Note Aug 2006 4.73
10 Year T-Note Sep 2006 4.63
10 Year T-Note Oct 2006 4.61
10 Year T-Note Nov 2006 4.46
10 Year T-Note Dec 2006 4.71
10 Year T-Note Jan 2007 4.83
10 Year T-Note Feb 2007 4.55
10 Year T-Note Mar 2007 4.65
10 Year T-Note Apr 2007 4.63
10 Year T-Note May 2007 4.89
10 Year T-Note Jun 2007 5.03
10 Year T-Note Jul 2007 4.77
10 Year T-Note Aug 2007 4.54
10 Year T-Note Sep 2007 4.58
10 Year T-Note Oct 2007 4.47
10 Year T-Note Nov 2007 3.97
10 Year T-Note Dec 2007 4.03
10 Year T-Note Jan 2008 3.64
10 Year T-Note Feb 2008 3.53
10 Year T-Note Mar 2008 3.43
10 Year T-Note Apr 2008 3.76
10 Year T-Note May 2008 4.05
10 Year T-Note Jun 2008 3.98
10 Year T-Note Jul 2008 3.98
10 Year T-Note Aug 2008 3.81
10 Year T-Note Sep 2008 3.83
10 Year T-Note Oct 2008 3.97
10 Year T-Note Nov 2008 2.96
10 Year T-Note Dec 2008 2.24
10 Year T-Note Jan 2009 2.84
10 Year T-Note Feb 2009 3.04
10 Year T-Note Mar 2009 2.68
10 Year T-Note Apr 2009 3.12
10 Year T-Note May 2009 3.46
10 Year T-Note Jun 2009 3.52
10 Year T-Note Jul 2009 3.5
10 Year T-Note Aug 2009 3.4
10 Year T-Note Sep 2009 3.31
10 Year T-Note Oct 2009 3.39
10 Year T-Note Nov 2009 3.2
10 Year T-Note Dec 2009 3.84
10 Year T-Note Jan 2010 3.61
10 Year T-Note Feb 2010 3.6
10 Year T-Note Mar 2010 3.7
AAPL Jan 2000 25.94
AAPL Feb 2000 28.66
AAPL Mar 2000 33.95
AAPL Apr 2000 31.01
AAPL May 2000 21
AAPL Jun 2000 26.19
AAPL Jul 2000 25.41
AAPL Aug 2000 30.47
AAPL Sep 2000 12.88
AAPL Oct 2000 9.78
AAPL Nov 2000 8.25
AAPL Dec 2000 7.44
AAPL Jan 2001 10.81
AAPL Feb 2001 9.12
AAPL Mar 2001 11.03
AAPL Apr 2001 12.74
AAPL May 2001 9.98
AAPL Jun 2001 11.62
AAPL Jul 2001 9.4
AAPL Aug 2001 9.27
AAPL Sep 2001 7.76
AAPL Oct 2001 8.78
AAPL Nov 2001 10.65
AAPL Dec 2001 10.95
AAPL Jan 2002 12.36
AAPL Feb 2002 10.85
AAPL Mar 2002 11.84
AAPL Apr 2002 12.14
AAPL May 2002 11.65
AAPL Jun 2002 8.86
AAPL Jul 2002 7.63
AAPL Aug 2002 7.38
AAPL Sep 2002 7.25
AAPL Oct 2002 8.03
AAPL Nov 2002 7.75
AAPL Dec 2002 7.16
AAPL Jan 2003 7.18
AAPL Feb 2003 7.51
AAPL Mar 2003 7.07
AAPL Apr 2003 7.11
AAPL May 2003 8.98
AAPL Jun 2003 9.53
AAPL Jul 2003 10.54
AAPL Aug 2003 11.31
AAPL Sep 2003 10.36
AAPL Oct 2003 11.44
AAPL Nov 2003 10.45
AAPL Dec 2003 10.69
AAPL Jan 2004 11.28
AAPL Feb 2004 11.96
AAPL Mar 2004 13.52
AAPL Apr 2004 12.89
AAPL May 2004 14.03
AAPL Jun 2004 16.27
AAPL Jul 2004 16.17
AAPL Aug 2004 17.25
AAPL Sep 2004 19.38
AAPL Oct 2004 26.2
AAPL Nov 2004 33.53
AAPL Dec 2004 32.2
AAPL Jan 2005 38.45
AAPL Feb 2005 44.86
AAPL Mar 2005 41.67
AAPL Apr 2005 36.06
AAPL May 2005 39.76
AAPL Jun 2005 36.81
AAPL Jul 2005 42.65
AAPL Aug 2005 46.89
AAPL Sep 2005 53.61
AAPL Oct 2005 57.59
AAPL Nov 2005 67.82
AAPL Dec 2005 71.89
AAPL Jan 2006 75.51
AAPL Feb 2006 68.49
AAPL Mar 2006 62.72
AAPL Apr 2006 70.39
AAPL May 2006 59.77
AAPL Jun 2006 57.27
AAPL Jul 2006 67.96
AAPL Aug 2006 67.85
AAPL Sep 2006 76.98
AAPL Oct 2006 81.08
AAPL Nov 2006 91.66
AAPL Dec 2006 84.84
AAPL Jan 2007 85.73
AAPL Feb 2007 84.61
AAPL Mar 2007 92.91
AAPL Apr 2007 99.8
AAPL May 2007 121.19
AAPL Jun 2007 122.04
AAPL Jul 2007 131.76
AAPL Aug 2007 138.48
AAPL Sep 2007 153.47
AAPL Oct 2007 189.95
AAPL Nov 2007 182.22
AAPL Dec 2007 198.08
AAPL Jan 2008 135.36
AAPL Feb 2008 125.02
AAPL Mar 2008 143.5
AAPL Apr 2008 173.95
AAPL May 2008 188.75
AAPL Jun 2008 167.44
AAPL Jul 2008 158.95
AAPL Aug 2008 169.53
AAPL Sep 2008 113.66
AAPL Oct 2008 107.59
AAPL Nov 2008 92.67
AAPL Dec 2008 85.35
AAPL Jan 2009 90.13
AAPL Feb 2009 89.31
AAPL Mar 2009 105.12
AAPL Apr 2009 125.83
AAPL May 2009 135.81
AAPL Jun 2009 142.43
AAPL Jul 2009 163.39
AAPL Aug 2009 168.21
AAPL Sep 2009 185.35
AAPL Oct 2009 188.5
AAPL Nov 2009 199.91
AAPL Dec 2009 210.73
AAPL Jan 2010 192.06
AAPL Feb 2010 204.62
AAPL Mar 2010 223.02
function timeSeriesChart() {
var margin = {top: 20, right: 20, bottom: 20, left: 20},
width = 760,
height = 120,
xValue = function(d) { return d[0]; },
yValue = function(d) { return d[1]; },
xScale = d3.scaleTime(),
yScale = d3.scaleLinear(),
xAxis = d3.axisBottom().scale(xScale).tickSize(6, 0),
area = d3.area().x(X).y1(Y),
line = d3.line().x(X).y(Y),
values = function (d){ return d; },
title = null,
titleX = -30,
titleY = 25,
xExtent = null;
function chart(selection) {
selection.each(function(d) {
// Convert data to standard representation greedily;
// this is needed for nondeterministic accessors.
var data = values(d).map(function(d, i) {
return [xValue.call(data, d, i), yValue.call(data, d, i)];
});
// Update the x-scale.
xScale
.domain(xExtent || d3.extent(data, function(d) { return d[0]; }))
.range([0, width - margin.left - margin.right]);
// Update the y-scale.
yScale
.domain([0, d3.max(data, function(d) { return d[1]; })])
.range([height - margin.top - margin.bottom, 0]);
// Select the svg element, if it exists.
var svg = d3.select(this).selectAll("svg").data([data]);
var svgEnter = svg.enter().append("svg");
// Otherwise, create the skeletal chart.
var gEnter = svgEnter.append("g");
gEnter.append("text").attr("class", "title");
gEnter.append("path").attr("class", "area");
gEnter.append("path").attr("class", "line");
gEnter.append("g").attr("class", "x axis");
// Update the outer dimensions.
svg = svg.merge(svgEnter);
svg .attr("width", width)
.attr("height", height);
// Update the inner dimensions.
var g = svg.select("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
// Update the area path.
g.select(".area")
.attr("d", area.y0(yScale.range()[0]));
// Update the line path.
g.select(".line")
.attr("d", line);
// Update the x-axis.
g.select(".x.axis")
.attr("transform", "translate(0," + yScale.range()[0] + ")")
.call(xAxis);
// Update the title.
if(title){
g.select(".title")
.attr("x", titleX)
.attr("y", titleY)
.attr("text-anchor", "end")
.text(title(d));
}
});
}
// The x-accessor for the path generator; xScale ∘ xValue.
function X(d) {
return xScale(d[0]);
}
// The x-accessor for the path generator; yScale ∘ yValue.
function Y(d) {
return yScale(d[1]);
}
chart.margin = function(_) {
if (!arguments.length) return margin;
margin = _;
return chart;
};
chart.width = function(_) {
if (!arguments.length) return width;
width = _;
return chart;
};
chart.height = function(_) {
if (!arguments.length) return height;
height = _;
return chart;
};
chart.x = function(_) {
if (!arguments.length) return xValue;
xValue = _;
return chart;
};
chart.y = function(_) {
if (!arguments.length) return yValue;
yValue = _;
return chart;
};
chart.values = function(_) {
if (!arguments.length) return values;
values = _;
return chart;
};
chart.title = function(_) {
if (!arguments.length) return title;
title = _;
return chart;
};
chart.titleX = function(_) {
if (!arguments.length) return titleX;
titleX = _;
return chart;
};
chart.titleY = function(_) {
if (!arguments.length) return titleY;
titleY = _;
return chart;
};
chart.xExtent = function(_) {
if (!arguments.length) return xExtent;
xExtent = _;
return chart;
};
return chart;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment