Skip to content

Instantly share code, notes, and snippets.

@AmritPatel
Created May 27, 2014 00:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AmritPatel/c24af1f90fd5f6370bfc to your computer and use it in GitHub Desktop.
Save AmritPatel/c24af1f90fd5f6370bfc to your computer and use it in GitHub Desktop.
"mt vernon va" search frequency over time to determine most popular months for visiting Washington's Mt. Vernon estate
<!doctype HTML>
<meta charset = 'utf-8'>
<html>
<head>
<link rel='stylesheet' href='http://nvd3.org/assets/css/nv.d3.css'>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js' type='text/javascript'></script>
<script src='http://d3js.org/d3.v3.min.js' type='text/javascript'></script>
<script src='http://timelyportfolio.github.io/rCharts_nvd3_tests/libraries/widgets/nvd3/js/nv.d3.min-new.js' type='text/javascript'></script>
<script src='http://nvd3.org/assets/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='chart450b3c4e0dc3' class='rChart nvd3'></div>
<script type='text/javascript'>
$(document).ready(function(){
drawchart450b3c4e0dc3()
});
function drawchart450b3c4e0dc3(){
var opts = {
"dom": "chart450b3c4e0dc3",
"width": 800,
"height": 400,
"x": "month",
"y": "avg_over_years",
"type": "multiBarChart",
"size": {
"const": 3
},
"id": "chart450b3c4e0dc3"
},
data = [
{
"month": "01",
"avg_over_years": -0.6590204081633
},
{
"month": "02",
"avg_over_years": -0.3163777777778
},
{
"month": "03",
"avg_over_years": 0.123
},
{
"month": "04",
"avg_over_years": 0.2861627906977
},
{
"month": "05",
"avg_over_years": 0.3238
},
{
"month": "06",
"avg_over_years": 0.3746904761905
},
{
"month": "07",
"avg_over_years": 0.4328222222222
},
{
"month": "08",
"avg_over_years": 0.0715
},
{
"month": "09",
"avg_over_years": 0.0253023255814
},
{
"month": "10",
"avg_over_years": -0.06817777777778
},
{
"month": "11",
"avg_over_years": -0.1735
},
{
"month": "12",
"avg_over_years": -0.3345909090909
}
]
if(!(opts.type==="pieChart" || opts.type==="sparklinePlus")) {
var data = d3.nest()
.key(function(d){
//return opts.group === undefined ? 'main' : d[opts.group]
//instead of main would think a better default is opts.x
return opts.group === undefined ? opts.y : d[opts.group];
})
.entries(data);
}
if (opts.disabled != undefined){
data.map(function(d, i){
d.disabled = opts.disabled[i]
})
}
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