Skip to content

Instantly share code, notes, and snippets.

@patilv
Created October 20, 2014 21:22
Show Gist options
  • Save patilv/b23659d523903d9a229c to your computer and use it in GitHub Desktop.
Save patilv/b23659d523903d9a229c 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 = 'chart1d782b211286' class = 'rChart nvd3'></div>
<script type='text/javascript'>
$(document).ready(function(){
drawchart1d782b211286()
});
function drawchart1d782b211286(){
var opts = {
"dom": "chart1d782b211286",
"width": 800,
"height": 600,
"x": "Degree",
"y": "Number",
"type": "multiBarHorizontalChart",
"id": "chart1d782b211286"
},
data = [
{
"Degree": "Business",
"Number": 366815,
"WSJPercent": 20.5,
"Percentage": 24.74784274833
},
{
"Degree": "Social Sciences or History",
"Number": 178543,
"WSJPercent": 10,
"Percentage": 12.04572901276
},
{
"Degree": "Health and related Programs",
"Number": 163440,
"WSJPercent": 9.1,
"Percentage": 11.02677758212
},
{
"Degree": "Psychology",
"Number": 108986,
"WSJPercent": 6.1,
"Percentage": 7.352939192152
},
{
"Degree": "Education",
"Number": 105785,
"WSJPercent": 5.9,
"Percentage": 7.136977891122
},
{
"Degree": "Biological and Biomedical Science",
"Number": 95849,
"WSJPercent": 5.4,
"Percentage": 6.466627535909
},
{
"Degree": "Visual and Performing Arts",
"Number": 95797,
"WSJPercent": 5.3,
"Percentage": 6.463119261103
},
{
"Degree": "Communications or Journalism",
"Number": 83770,
"WSJPercent": 4.7,
"Percentage": 5.651695778601
},
{
"Degree": "Engineering",
"Number": 81382,
"WSJPercent": 4.5,
"Percentage": 5.490585004824
},
{
"Degree": "English or Literature",
"Number": 53767,
"WSJPercent": 3,
"Percentage": 3.62748868244
},
{
"Degree": "Homeland security or Law enforcement or Firefighting",
"Number": 53767,
"WSJPercent": 3,
"Percentage": 3.62748868244
},
{
"Degree": "Computer and information sciences",
"Number": 47384,
"WSJPercent": 2.6,
"Percentage": 3.196847950021
},
{
"Degree": "Liberal arts and sciences or general studies or humanities",
"Number": 46925,
"WSJPercent": 2.6,
"Percentage": 3.165880678177
}
]
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} )
.color([ "#999999", "#002865" ])
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