Created
November 1, 2013 18:00
-
-
Save renecnielsen/7269282 to your computer and use it in GitHub Desktop.
Line Chart
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> | |
<html> | |
<head> | |
<link rel='stylesheet' href='http://nvd3.org/src/nv.d3.css'> | |
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js' type='text/javascript'></script> | |
<script src='http://d3js.org/d3.v2.min.js' type='text/javascript'></script> | |
<script src='http://nvd3.org/nv.d3.js' type='text/javascript'></script> | |
<script src='http://nvd3.org/lib/fisheye.js' type='text/javascript'></script> | |
<style> | |
.rChart { | |
display: block; | |
margin-left: auto; | |
margin-right: auto; | |
width: 800px; | |
height: 400px; | |
} | |
</style> | |
</head> | |
<body> | |
<div id='chart8def6233b9e6' class='rChart nvd3'></div> | |
<script type='text/javascript'> | |
$(document).ready(function(){ | |
drawchart8def6233b9e6() | |
}); | |
function drawchart8def6233b9e6(){ | |
var opts = { | |
"dom": "chart8def6233b9e6", | |
"width": 800, | |
"height": 400, | |
"x": "month", | |
"y": "count", | |
"group": "EventCode", | |
"type": "lineChart", | |
"id": "chart8def6233b9e6" | |
}, | |
data = [ | |
{ | |
"month": 2007.9, | |
"EventCode": " Make statement, not specified below", | |
"count": 532 | |
}, | |
{ | |
"month": 2007.9, | |
"EventCode": " Make an appeal or request, not specified below", | |
"count": 326 | |
}, | |
{ | |
"month": 2007.9, | |
"EventCode": " Express intent to meet or negotiate", | |
"count": 163 | |
}, | |
{ | |
"month": 2007.9, | |
"EventCode": " Consult, not specified below", | |
"count": 232 | |
}, | |
{ | |
"month": 2007.9, | |
"EventCode": " Make a visit", | |
"count": 447 | |
}, | |
{ | |
"month": 2007.9, | |
"EventCode": " Host a visit", | |
"count": 425 | |
}, | |
{ | |
"month": 2007.9, | |
"EventCode": " Praise or endorse", | |
"count": 208 | |
}, | |
{ | |
"month": 2007.9, | |
"EventCode": " Accuse, not specified below", | |
"count": 200 | |
}, | |
{ | |
"month": 2007.9, | |
"EventCode": " Arrest, detain, or charge with legal action", | |
"count": 156 | |
}, | |
{ | |
"month": 2007.9, | |
"EventCode": " Use conventional military force, not specified below", | |
"count": 381 | |
} | |
] | |
var data = d3.nest() | |
.key(function(d){ | |
return opts.group === undefined ? 'main' : d[opts.group] | |
}) | |
.entries(data) | |
nv.addGraph(function() { | |
var chart = nv.models[opts.type]() | |
.x(function(d) { return d[opts.x] }) | |
.y(function(d) { return d[opts.y] }) | |
.width(opts.width) | |
.height(opts.height) | |
d3.select("#" + opts.id) | |
.append('svg') | |
.datum(data) | |
.transition().duration(500) | |
.call(chart); | |
nv.utils.windowResize(chart.update); | |
return chart; | |
}); | |
}; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment