Skip to content

Instantly share code, notes, and snippets.

@KamaleshRao
Last active August 22, 2016 02:05
Show Gist options
  • Save KamaleshRao/9984606 to your computer and use it in GitHub Desktop.
Save KamaleshRao/9984606 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
font: 10px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
/*.x.axis path {
display: none;
}*/
.line {
fill: none;
stroke: steelblue;
stroke-width: 1.5px;
}
</style>
<body>
<h1>Average Monthly Temperature of Lake Toxoway, NC</h1>
<script src="http://d3js.org/d3.v3.js"></script>
<script>
var f = function(property){
return function(obj){ return obj[property]; };
}
var margin = {top: 20, right: 20, bottom: 30, left: 50},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
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 + ")");
d3.tsv("toxdata2.txt", function(error, data) {
data.forEach(function(d){
d.dateformat=d3.time.format('%d-%b-%Y').parse(d.DateFormat);
d.month=+d.dateformat.getMonth()+1;
d.temp=+d.MeanTemp/10*9/5+32;
d.precip=+d.Precip/10*0.0393701;
})
/* var mintemp = d3.min(data, f('temp'))
var maxtemp = d3.max(data, f('temp'))
var mindate = d3.min(data, f('dateformat'))
var maxdate = d3.max(data, f('dateformat'))*/
var x = d3.time.scale()
.domain(d3.extent(data, f('dateformat')))
.range([0, width])
var y = d3.time.scale()
.domain(d3.extent(data, f('temp')))
.range([height, 0])
var formatAsNumber = d3.format(".1");
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(y)
.orient("left")
.tickFormat(formatAsNumber);
svg.selectAll('circle')
.data(data).enter()
.append('circle')
.attr('r',2)
.attr('cx', function(d){ return x(d.dateformat); })
.attr('cy', function(d){ return y(d.temp);})
.attr('opacity',.2)
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.append("text")
.attr("class", "label")
.attr("x", width)
.attr("y", -6)
.style("text-anchor", "end")
.text("Year")
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("class", "label")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Temperature (F)");
line=d3.svg.line()
.x(function(d){return x(d.dateformat);})
.y(function(d){return y(d.temp);})
svg.append('path')
.datum(data)
.attr('d',line)
.style('fill','None')
.style('stroke','blue')
debugger;
});
</script>
Date DateFormat MaxPrecip MaxSnowDpth Precip Snow MaxTemp MeanTemp MinTemp
19960301 1-Mar-1996 452 25 1464 0 117 -16 50
19960401 1-Apr-1996 343 0 1303 0 208 23 118
19960501 1-May-1996 437 0 1396 0 276 99 188
19960601 1-Jun-1996 1008 0 2374 0 281 133 207
19960701 1-Jul-1996 914 0 2415 0 291 153 222
19960801 1-Aug-1996 732 0 3114 0 259 149 204
19960901 1-Sep-1996 1110 0 4046 0 227 111 169
19961001 1-Oct-1996 183 0 527 0 184 52 118
19961101 1-Nov-1996 1214 0 2396 0 108 -1 53
19961201 1-Dec-1996 1435 127 2895 114 91 -27 32
19970101 1-Jan-1997 523 76 2111 76 77 -34 22
19970201 1-Feb-1997 531 76 2341 46 115 -18 48
19970301 1-Mar-1997 1654 0 3338 0 187 25 106
19970401 1-Apr-1997 792 0 2491 0 198 16 107
19970501 1-May-1997 434 0 1234 0 226 67 146
19970601 1-Jun-1997 429 0 2126 0 237 129 183
19970701 1-Jul-1997 696 0 1515 0 294 156 225
19970801 1-Aug-1997 89 0 234 0 266 133 199
19970901 1-Sep-1997 711 0 1970 0 228 123 175
19971001 1-Oct-1997 587 0 1677 0 187 57 122
19971101 1-Nov-1997 173 0 833 0 103 -21 41
19971201 1-Dec-1997 305 127 1458 147 89 -31 29
19980101 1-Jan-1998 1943 127 5554 267 85 -22 31
19980201 1-Feb-1998 800 0 3317 0 102 -19 41
19980301 1-Mar-1998 866 25 2430 28 124 -1 61
19980401 1-Apr-1998 724 0 3417 0 192 41 116
19980501 1-May-1998 272 0 930 0 254 111 182
19980601 1-Jun-1998 224 0 1096 0 286 144 215
19980701 1-Jul-1998 173 0 554 0 278 165 222
19980801 1-Aug-1998 305 0 1237 0 282 148 215
19980901 1-Sep-1998 213 0 712 0 257 128 192
19981001 1-Oct-1998 922 2257 0 191 63 127
19981101 1-Nov-1998 841 0 1568 0 141 23 82
19981201 1-Dec-1998 417 51 1444 38 114 0 57
19990101 1-Jan-1999 886 0 2567 0 96 -24 36
19990201 1-Feb-1999 648 76 1936 89 101 -27 37
19990301 1-Mar-1999 191 102 1163 186 134 -17 59
19990401 1-Apr-1999 1270 0 1929 0 211 59 135
19990501 1-May-1999 325 0 874 0 248 77 163
19990601 1-Jun-1999 551 0 1701 0 245 127 186
19990701 1-Jul-1999 442 0 1531 0 266 162 214
19990801 1-Aug-1999 465 0 872 0 279 150 214
19990901 1-Sep-1999 749 0 1699 0 258 98 178
19991001 1-Oct-1999 1194 0 1901 0 182 54 118
19991101 1-Nov-1999 1488 0 2700 0 162 26 94
19991201 1-Dec-1999 551 0 1120 0 95 -35 30
20000101 1-Jan-2000 538 127 1448 147 75 -48 14
20000201 1-Feb-2000 391 76 861 0 126 -27 49
20000301 1-Mar-2000 391 0 936 0 184 9 97
20000401 1-Apr-2000 457 0 1878 0 201 34 117
20000501 1-May-2000 683 0 1314 0 269 103 186
20000601 1-Jun-2000 381 0 1582 0 263 137 200
20000701 1-Jul-2000 366 0 1684 0 267 163 215
20000801 1-Aug-2000 508 0 1604 0 275 153 214
20000901 1-Sep-2000 635 0 1897 0 213 117 165
20001001 1-Oct-2000 10 0 10 0 191 50 121
20001101 1-Nov-2000 1201 0 2489 127 114 3 58
20001201 1-Dec-2000 467 178 1068 280 47 -67 -10
20010101 1-Jan-2001 434 0 1326 13 67 -55 6
20010201 1-Feb-2001 546 0 1277 0 116 -15 51
20010301 1-Mar-2001 533 305 1498 337 123 -10 56
20010401 1-Apr-2001 97 0 329 0 230 60 145
20010501 1-May-2001 279 0 1272 0 243 90 167
20010601 1-Jun-2001 434 0 1972 0 238 135 186
20010701 1-Jul-2001 678 0 1754 0 244 158 201
20010801 1-Aug-2001 282 0 1074 0 259 167 213
20010901 1-Sep-2001 528 0 2029 0 228 109 168
20011001 1-Oct-2001 742 0 1217 0 182 28 105
20011101 1-Nov-2001 610 0 1182 0 175 17 96
20011201 1-Dec-2001 328 0 1178 0 113 -6 54
20020101 1-Jan-2002 381 76 1613 109 103 -35 34
20020201 1-Feb-2002 361 0 626 0 110 -40 35
20020301 1-Mar-2002 572 0 2735 0 153 7 80
20020401 1-Apr-2002 361 0 1406 0 240 75 158
20020501 1-May-2002 432 0 1497 0 240 87 164
20020601 1-Jun-2002 315 0 1222 0 277 150 213
20020701 1-Jul-2002 279 0 1112 0 283 169 226
20020801 1-Aug-2002 627 0 1665 0 276 155 216
20020901 1-Sep-2002 1410 0 5611 0 227 144 186
20021001 1-Oct-2002 732 0 1699 0 181 97 139
20021101 1-Nov-2002 579 0 2042 0 102 -6 48
20021201 1-Dec-2002 686 25 2735 0 83 -26 28
20030101 1-Jan-2003 838 102 1809 89 62 -57 4
20030201 1-Feb-2003 876 102 2142 127 92 -25 34
20030301 1-Mar-2003 594 25 2089 25 160 26 93
20030401 1-Apr-2003 554 0 2168 0 200 47 123
20030501 1-May-2003 917 0 3607 0 222 113 168
20030601 1-Jun-2003 1234 0 3558 0 247 130 189
20030701 1-Jul-2003 2324 0 4067 0 252 156 204
20030801 1-Aug-2003 681 0 3456 0 252 161 206
20030901 1-Sep-2003 2014 0 4649 0 214 110 162
20031001 1-Oct-2003 551 0 916 0 168 48 108
20031101 1-Nov-2003 2464 0 4236 0 170 29 99
20031201 1-Dec-2003 742 102 2205 153 83 -43 20
20040101 1-Jan-2004 213 51 762 50 94 -42 26
20040201 1-Feb-2004 635 102 2184 102 72 -33 20
20040301 1-Mar-2004 163 25 804 20 156 10 83
20040401 1-Apr-2004 818 0 1201 0 189 46 118
20040501 1-May-2004 958 0 2044 0 222 120 171
20040601 1-Jun-2004 582 0 2670 0 227 146 187
20040701 1-Jul-2004 1285 0 5984 0 236 154 195
20040801 1-Aug-2004 287 0 1446 0 221 141 181
20040901 1-Sep-2004 3660 0 7564 0 218 124 171
20041001 1-Oct-2004 99 0 317 0 180 88 134
20041101 1-Nov-2004 602 0 1618 0 159 37 98
20041201 1-Dec-2004 1173 0 2522 0 96 -39 29
20050101 1-Jan-2005 554 51 1158 51 107 -25 41
20050201 1-Feb-2005 259 25 1187 30 95 -15 40
20050301 1-Mar-2005 1148 0 2257 16 117 -4 57
20050401 1-Apr-2005 290 0 1438 0 174 40 107
20050501 1-May-2005 290 0 880 0 215 80 149
20050601 1-Jun-2005 1676 0 5366 0 221 140 181
20050701 1-Jul-2005 1237 0 6055 0 240 165 203
20050801 1-Aug-2005 419 0 2321 0 236 165 201
20050901 1-Sep-2005 183 0 419 0 233 124 179
20051001 1-Oct-2005 577 0 853 0 175 76 126
20051101 1-Nov-2005 1242 0 2356 0 132 32 84
20051201 1-Dec-2005 417 0 1783 0 77 -36 20
20060101 1-Jan-2006 658 0 2234 0 113 -11 52
20060201 1-Feb-2006 762 152 1267 153 77 -30 24
20060301 1-Mar-2006 279 25 470 33 126 8 66
20060401 1-Apr-2006 318 0 934 0 213 62 137
20060501 1-May-2006 277 0 567 0 198 85 141
20060601 1-Jun-2006 724 0 1849 0 242 134 188
20060701 1-Jul-2006 373 0 1329 0 244 156 200
20060801 1-Aug-2006 620 0 2237 0 242 162 202
20060901 1-Sep-2006 808 0 2702 0 193 113 153
20061001 1-Oct-2006 566 0 1333 0 160 56 108
20061101 1-Nov-2006 1105 0 2011 0 142 5 75
20061201 1-Dec-2006 1280 0 3330 0 123 3 63
20070101 1-Jan-2007 747 0 1672 0 91 -23 35
20070201 1-Feb-2007 229 25 644 25 87 -46 21
20070301 1-Mar-2007 1270 0 1750 0 175 33 103
20070401 1-Apr-2007 414 25 871 25 175 35 105
20070501 1-May-2007 188 0 600 0 223 85 154
20070601 1-Jun-2007 866 0 2292 0 243 131 187
20070701 1-Jul-2007 904 0 1696 0 249 153 200
20070801 1-Aug-2007 170 0 635 0 274 167 220
20070901 1-Sep-2007 566.5 0 1303.5 0 232 126 179
20071001 1-Oct-2007 937.5 0 2121.5 0 181 82 131
20071101 1-Nov-2007 245.5 0 517.5 0 131 2 66
20071201 1-Dec-2007 473.5 12.5 1432 57 103 -5 49
20080101 1-Jan-2008 623.5 82.5 1442 144.5 67 -51 8
20080201 1-Feb-2008 641.5 0 2060 0 104 -22 41
20080301 1-Mar-2008 1241 0 3671 0 130 -12 59
20080401 1-Apr-2008 363.5 0 1179.5 0 196 51 123
20080501 1-May-2008 123.5 0 530 0 208 85 146
20080601 1-Jun-2008 133.5 0 360 0 257 137 197
20080701 1-Jul-2008 373.5 0 1331.5 0 252 138 195
20080801 1-Aug-2008 1361.5 0 2543.5 0 243 149 196
20080901 1-Sep-2008 326.5 0 430.5 0 218 131 174
20081001 1-Oct-2008 800 0 1260 0 160 46 103
20081101 1-Nov-2008 340 0 963 0 121 -6 57
20081201 1-Dec-2008 529.5 0 2217.5 0 103 1 52
20090101 1-Jan-2009 715 6.5 1358 28 76 -27 24
20090201 1-Feb-2009 406.5 0 928 4 96 -32 32
20090301 1-Mar-2009 569 0 2208.5 15.5 137 3 70
20090401 1-Apr-2009 592 0 1668 0 180 35 108
20090501 1-May-2009 641.5 0 2404 0 197 102 150
20090601 1-Jun-2009 394 0 726 0 242 141 192
20090701 1-Jul-2009 289.5 0 1072.5 0 229 138 184
20090801 1-Aug-2009 440.5 0 1596 0 231 150 190
20090901 1-Sep-2009 1630.5 0 5487.5 0 204 128 166
20091001 1-Oct-2009 1124 0 2864 0 155 57 106
20091101 1-Nov-2009 800.5 0 2037 0 148 31 89
20091201 1-Dec-2009 936 57.5 2814 57 74 -35 19
20100101 1-Jan-2010 1002 165 3225 169 54 -59 -2
20100201 1-Feb-2010 331.5 228.5 753 197 42 -63 -10
20100301 1-Mar-2010 481.5 127 1573 129.5 111 -3 54
20100401 1-Apr-2010 965 0 1361 0 217 47 132
20100501 1-May-2010 460 0 1389.5 0 209 112 160
20100601 1-Jun-2010 437.6666667 0 1367.333333 0 249 157 203
20100701 1-Jul-2010 243 0 1211.666667 0 250 167 209
20100801 1-Aug-2010 648.6666667 0 1528 0 241 171 206
20100901 1-Sep-2010 391 0 1046.666667 0 227 119 173
20101001 1-Oct-2010 652 0 1469.333333 0 178 49 113
20101101 1-Nov-2010 1141.333333 0 1776.666667 0 132 6 69
20101201 1-Dec-2010 790.3333333 190.6666667 1069 200.6666667 40 -71 -15
20110101 1-Jan-2011 292.6666667 190.5 742.6666667 148.5 49 -56 -3
20110201 1-Feb-2011 559.6666667 25 842 25 108 -13 48
20110301 1-Mar-2011 1916.666667 0 3812 0 132 22 77
20110401 1-Apr-2011 1699 0 2616.5 0 195 61 128
20110501 1-May-2011 236 0 498 0 207 94 151
20110601 1-Jun-2011 169 0 485 0 251 145 198
20110701 1-Jul-2011 524.5 0 2190.5 0 243 168 205
20110801 1-Aug-2011 357 0 688 0 246 155 201
20110901 1-Sep-2011 1740 0 3539 0 231 131 181
20111001 1-Oct-2011 254 0 794 0 168 46 107
20111101 1-Nov-2011 1300.5 0 3221.5 4 129 14 72
20111201 1-Dec-2011 760.5 0 2370.5 0 105 -7 49
20120101 1-Jan-2012 491.5 25 2089.5 10.5 94 -20 37
20120201 1-Feb-2012 139.5 6.5 436.5 6.5 111 -24 43
20120301 1-Mar-2012 575.5 0 1251.5 0 176 55 115
20120401 1-Apr-2012 623.5 0 1407 0 193 55 124
20120501 1-May-2012 542.5 0 1692.5 0 240 125 182
20120601 1-Jun-2012 326.5 0 962.5 0 226 133 180
20120701 1-Jul-2012 621.6666667 0 2677 0 251 174 213
20120801 1-Aug-2012 244 0 1227.333333 0 194 139 167
20120901 1-Sep-2012 1162 2798.5 0
20121001 1-Oct-2012 1079.5 1539.5 0
20121101 1-Nov-2012 105.5 13 210.5 6.5
20121201 1-Dec-2012 692.5 0 1162.5 0
20130101 1-Jan-2013 1381 2.5 3386.666667 3.333333333
20130201 1-Feb-2013 621.3333333 53.33333333 1693 142.6666667
20130301 1-Mar-2013 554.3333333 21.33333333 1276.666667 27.33333333
20130401 1-Apr-2013 1172.666667 0 3058 0
20130501 1-May-2013 803.3333333 0 2163 0 202 107 155
20130601 1-Jun-2013 1171 0 3820 0 230 160 195
20130701 1-Jul-2013 1523.333333 0 5684.666667 0 222 173 198
20130801 1-Aug-2013 520.6666667 0 2005.666667 0 235 169 202
20130901 1-Sep-2013 495 1105.333333 0 227 141 184
20131001 1-Oct-2013 497 0 650.3333333 0 180 94 137
20131101 1-Nov-2013 1055.666667 4 2289 6 119 17 68
20131201 1-Dec-2013 1107.333333 0 3934 0 103 25 64
20140101 1-Jan-2014 404 34 890.6666667 43.66666667 57 -68 -3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment