Skip to content

Instantly share code, notes, and snippets.

@DrSleep
Created June 12, 2014 21:17
Show Gist options
  • Save DrSleep/723cce02da2836c06e78 to your computer and use it in GitHub Desktop.
Save DrSleep/723cce02da2836c06e78 to your computer and use it in GitHub Desktop.
Liverpool2
<!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='chart818535469c8' class='rChart nvd3'></div>
<script type='text/javascript'>
$(document).ready(function(){
drawchart818535469c8()
});
function drawchart818535469c8(){
var opts = {
"dom": "chart818535469c8",
"width": 800,
"height": 400,
"x": "Variable",
"y": "Count",
"group": "Club",
"type": "multiBarChart",
"id": "chart818535469c8"
},
data = [
{
"Club": "Liverpool",
"Variable": "ForwardGoals",
"Count": 52
},
{
"Club": "Liverpool",
"Variable": "MidfieldersGoals",
"Count": 33
},
{
"Club": "Liverpool",
"Variable": "DefendersGoals",
"Count": 11
},
{
"Club": "Liverpool",
"Variable": "GoalkeeperGoals",
"Count": 0
},
{
"Club": "Liverpool",
"Variable": "AutoGoals",
"Count": 5
}
]
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