Skip to content

Instantly share code, notes, and snippets.

@jsindos
Created October 23, 2015 00:43
Show Gist options
  • Save jsindos/b54b12b00fae9aeffeaf to your computer and use it in GitHub Desktop.
Save jsindos/b54b12b00fae9aeffeaf to your computer and use it in GitHub Desktop.
<html>
<head>
<title>NVD3 Tooltip Bug</title>
<script src="https://rawgit.com/mbostock/d3/master/d3.js"></script>
<script src="https://rawgit.com/novus/nvd3/master/build/nv.d3.js"></script>
<link rel="stylesheet" href="https://rawgit.com/novus/nvd3/master/build/nv.d3.css">
</head>
<body>
<div id="stackedchart">
<svg></svg>
</div>
<script>
nv.addGraph(function() {
var chart = nv.models.stackedAreaChart();
d3.select('#stackedchart svg')
.datum(sinAndCos())
.call(chart);
nv.utils.windowResize(chart.update);
return chart;
});
/**************************************
* Simple test data generator
*/
function sinAndCos() {
var sin = [],sin2 = [],
cos = [];
//Data is represented as an array of {x,y} pairs.
for (var i = 0; i < 100; i++) {
sin.push({x: i, y: Math.sin(i/10)});
sin2.push({x: i, y: Math.sin(i/10) *0.25 + 0.5});
cos.push({x: i, y: .5 * Math.cos(i/10)});
}
//Line chart data should be sent as an array of series objects.
return [
{
values: sin, //values - represents the array of {x,y} data points
key: 'Sine Wave', //key - the name of the series.
color: '#ff7f0e' //color - optional: choose your own line color.
},
{
values: cos,
key: 'Cosine Wave',
color: '#2ca02c'
},
{
values: sin2,
key: 'Another sine wave',
color: '#7777ff',
area: true //area - set to true if you want this line to turn into a filled area chart.
}
];
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment