Last active
August 29, 2015 14:23
-
-
Save jes-moore/41974692cc3be209296e to your computer and use it in GitHub Desktop.
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 > | |
<div id = 'chart3a9866b04b74' class = 'rChart nvd3'></div> | |
<script type='text/javascript'> | |
$(document).ready(function(){ | |
drawchart3a9866b04b74() | |
}); | |
function drawchart3a9866b04b74(){ | |
var opts = { | |
"dom": "chart3a9866b04b74", | |
"width": 800, | |
"height": 400, | |
"x": "tall", | |
"y": "age", | |
"type": "scatterChart", | |
"id": "chart3a9866b04b74" | |
}, | |
data = [ | |
{ | |
"age": 1, | |
"tall": 0.5, | |
"name": "a1", | |
"links": "http://example.com/a1" | |
}, | |
{ | |
"age": 2, | |
"tall": 0.5736842105263, | |
"name": "b2", | |
"links": "http://example.com/b2" | |
}, | |
{ | |
"age": 3, | |
"tall": 0.6473684210526, | |
"name": "c3", | |
"links": "http://example.com/c3" | |
}, | |
{ | |
"age": 4, | |
"tall": 0.7210526315789, | |
"name": "d4", | |
"links": "http://example.com/d4" | |
}, | |
{ | |
"age": 5, | |
"tall": 0.7947368421053, | |
"name": "e5", | |
"links": "http://example.com/e5" | |
}, | |
{ | |
"age": 6, | |
"tall": 0.8684210526316, | |
"name": "f6", | |
"links": "http://example.com/f6" | |
}, | |
{ | |
"age": 7, | |
"tall": 0.9421052631579, | |
"name": "g7", | |
"links": "http://example.com/g7" | |
}, | |
{ | |
"age": 8, | |
"tall": 1.015789473684, | |
"name": "h8", | |
"links": "http://example.com/h8" | |
}, | |
{ | |
"age": 9, | |
"tall": 1.089473684211, | |
"name": "i9", | |
"links": "http://example.com/i9" | |
}, | |
{ | |
"age": 10, | |
"tall": 1.163157894737, | |
"name": "j10", | |
"links": "http://example.com/j10" | |
}, | |
{ | |
"age": 11, | |
"tall": 1.236842105263, | |
"name": "k11", | |
"links": "http://example.com/k11" | |
}, | |
{ | |
"age": 12, | |
"tall": 1.310526315789, | |
"name": "l12", | |
"links": "http://example.com/l12" | |
}, | |
{ | |
"age": 13, | |
"tall": 1.384210526316, | |
"name": "m13", | |
"links": "http://example.com/m13" | |
}, | |
{ | |
"age": 14, | |
"tall": 1.457894736842, | |
"name": "n14", | |
"links": "http://example.com/n14" | |
}, | |
{ | |
"age": 15, | |
"tall": 1.531578947368, | |
"name": "o15", | |
"links": "http://example.com/o15" | |
}, | |
{ | |
"age": 16, | |
"tall": 1.605263157895, | |
"name": "p16", | |
"links": "http://example.com/p16" | |
}, | |
{ | |
"age": 17, | |
"tall": 1.678947368421, | |
"name": "q17", | |
"links": "http://example.com/q17" | |
}, | |
{ | |
"age": 18, | |
"tall": 1.752631578947, | |
"name": "r18", | |
"links": "http://example.com/r18" | |
}, | |
{ | |
"age": 19, | |
"tall": 1.826315789474, | |
"name": "s19", | |
"links": "http://example.com/s19" | |
}, | |
{ | |
"age": 20, | |
"tall": 1.9, | |
"name": "t20", | |
"links": "http://example.com/t20" | |
} | |
] | |
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 | |
.tooltipContent( function(key, x, y, e ){ | |
d3.selectAll('[class*=\"nv-path\"]').on('click',function(){ | |
//uncomment debugger if you want to see what you have | |
//debugger; | |
window.open(d3.select(this).datum().data['point'][4].links,'_blank'); | |
//as stated in the r code generating this | |
//the link address might be in the data that we already have | |
//window.open( | |
// 'http://example.com/' + d3.select(this).datum().data['point'][4].name, | |
// '_blank' | |
//); | |
}) | |
//looks like the actual point is below the hover tooltip path | |
//if tooltips disabled we could do click on the actual points | |
//d3.selectAll('.nv-group circle').on('click',function(){ | |
// debugger; | |
//}) | |
var d = e.series.values[e.pointIndex]; | |
return 'x: ' + x + ' y: ' + y + ' name: ' + d.name | |
} ) | |
chart.xAxis | |
.axisLabel("Date") | |
chart.yAxis | |
.axisLabel("Share Price") | |
.width( 50) | |
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