Last active
August 29, 2015 14:10
-
-
Save mhdatie/075053ce65ef4dd79ccf to your computer and use it in GitHub Desktop.
BarChart
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> | |
<meta charset = 'utf-8'> | |
<html> | |
<head> | |
<link rel='stylesheet' href='//cdnjs.cloudflare.com/ajax/libs/nvd3/1.1.15-beta/nv.d3.min.css'> | |
<script src='//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js' type='text/javascript'></script> | |
<script src='//d3js.org/d3.v3.min.js' type='text/javascript'></script> | |
<script src='//cdnjs.cloudflare.com/ajax/libs/nvd3/1.1.15-beta/nv.d3.min.js' type='text/javascript'></script> | |
<script src='//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 > | |
<p>A plot that represents the number of times each institute was chosen to raise additional awareness to Cyberbullying.</p> | |
<a href="https://docs.google.com/forms/d/1NZgovxTY3mXr_omDk8t9LCe_hWcV_S1-PL55CIMsMJ8/viewform?usp=send_form">Your opinion matters!</a> | |
<div id = 'chart58e3bf369e0' class = 'rChart nvd3'></div> | |
<script type='text/javascript'> | |
$(document).ready(function(){ | |
drawchart58e3bf369e0() | |
}); | |
function drawchart58e3bf369e0(){ | |
var opts = { | |
"dom": "chart58e3bf369e0", | |
"width": 800, | |
"height": 400, | |
"x": "Var1", | |
"y": "Freq", | |
"type": "discreteBarChart", | |
"id": "chart58e3bf369e0" | |
}, | |
data = [ | |
{ | |
"Var1": "Colleges", | |
"Freq": 40 | |
}, | |
{ | |
"Var1": "High Schools", | |
"Freq": 70 | |
}, | |
{ | |
"Var1": "Primary Schools", | |
"Freq": 61 | |
}, | |
{ | |
"Var1": "Private/Public Institutions", | |
"Freq": 39 | |
}, | |
{ | |
"Var1": "Social Networks/Media", | |
"Freq": 60 | |
}, | |
{ | |
"Var1": "Universities", | |
"Freq": 35 | |
} | |
] | |
if(!(opts.type==="pieChart" || opts.type==="sparklinePlus" || opts.type==="bulletChart")) { | |
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]() | |
.width(opts.width) | |
.height(opts.height) | |
if (opts.type != "bulletChart"){ | |
chart | |
.x(function(d) { return d[opts.x] }) | |
.y(function(d) { return d[opts.y] }) | |
} | |
d3.select("#" + opts.id) | |
.append('svg') | |
.datum(data) | |
.transition().duration(500) | |
.call(chart); | |
nv.utils.windowResize(chart.update); | |
return chart; | |
}); | |
}; | |
</script> | |
<script></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment