Skip to content

Instantly share code, notes, and snippets.

@patilv
Created October 20, 2014 21:14
Show Gist options
  • Save patilv/043b067f9dc040afd543 to your computer and use it in GitHub Desktop.
Save patilv/043b067f9dc040afd543 to your computer and use it in GitHub Desktop.
np1wsjmod
<!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: 600px;
}
</style>
</head>
<body >
<div id = 'chart1d785cc42c27' class = 'rChart nvd3'></div>
<script type='text/javascript'>
$(document).ready(function(){
drawchart1d785cc42c27()
});
function drawchart1d785cc42c27(){
var opts = {
"dom": "chart1d785cc42c27",
"width": 800,
"height": 600,
"x": "Degree",
"y": "Number",
"type": "multiBarHorizontalChart",
"id": "chart1d785cc42c27"
},
data = [
{
"Degree": "Business",
"Number": 366815,
"WSJPercent": 20.5
},
{
"Degree": "Social Sciences or History",
"Number": 178543,
"WSJPercent": 10
},
{
"Degree": "Health and related Programs",
"Number": 163440,
"WSJPercent": 9.1
},
{
"Degree": "Psychology",
"Number": 108986,
"WSJPercent": 6.1
},
{
"Degree": "Education",
"Number": 105785,
"WSJPercent": 5.9
},
{
"Degree": "Biological and Biomedical Science",
"Number": 95849,
"WSJPercent": 5.4
},
{
"Degree": "Visual and Performing Arts",
"Number": 95797,
"WSJPercent": 5.3
},
{
"Degree": "Communications or Journalism",
"Number": 83770,
"WSJPercent": 4.7
},
{
"Degree": "Engineering",
"Number": 81382,
"WSJPercent": 4.5
},
{
"Degree": "English or Literature",
"Number": 53767,
"WSJPercent": 3
},
{
"Degree": "Homeland security or Law enforcement or Firefighting",
"Number": 53767,
"WSJPercent": 3
},
{
"Degree": "Computer and information sciences",
"Number": 47384,
"WSJPercent": 2.6
},
{
"Degree": "Liberal arts and sciences or general studies or humanities",
"Number": 46925,
"WSJPercent": 2.6
}
]
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] })
}
chart
.margin({
"top": 30,
"right": 20,
"bottom": 20,
"left": 400
})
.showLegend(false)
.showControls(false)
.tooltipContent( function(key, x, y, WSJPercent)
{return key + ':' + y + '<br>'+ 'Degree:' + x + '<br>'+
'Percent:'+ WSJPercent.point.WSJPercent} )
chart.yAxis
.tickFormat(d3.format(',f'))
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