2012-05-22 23:16:42 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<link href="../src/d3.css" rel="stylesheet" type="text/css">
|
|
|
|
<style>
|
|
|
|
|
|
|
|
body {
|
|
|
|
overflow-y:scroll;
|
|
|
|
}
|
|
|
|
|
|
|
|
text {
|
|
|
|
font: 12px sans-serif;
|
|
|
|
}
|
|
|
|
|
|
|
|
</style>
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<svg id="test1"></svg>
|
|
|
|
|
|
|
|
<script src="../lib/d3.v2.js"></script>
|
|
|
|
<script src="../nv.d3.js"></script>
|
|
|
|
<script src="../src/models/historicalBar.js"></script>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
|
|
|
|
nv.addGraph({
|
|
|
|
generate: function() {
|
|
|
|
var width = nv.utils.windowSize().width - 40,
|
|
|
|
height = nv.utils.windowSize().height - 40;
|
|
|
|
|
|
|
|
var chart = nv.models.historicalBar()
|
|
|
|
.width(width)
|
|
|
|
.height(height);
|
|
|
|
|
|
|
|
d3.select("#test1")
|
|
|
|
.attr('width', width)
|
|
|
|
.attr('height', height)
|
|
|
|
.datum(sinData())
|
|
|
|
.call(chart);
|
|
|
|
|
|
|
|
return chart;
|
|
|
|
},
|
|
|
|
callback: function(graph) {
|
|
|
|
|
2012-05-24 06:22:58 +00:00
|
|
|
graph.dispatch.on('elementMouseover', function(e) {
|
2012-05-22 23:16:42 +00:00
|
|
|
var offsetElement = document.getElementById("chart"),
|
|
|
|
left = e.pos[0],
|
|
|
|
top = e.pos[1];
|
|
|
|
|
|
|
|
/*
|
|
|
|
var content = '<h3>' + e.label + '</h3>' +
|
|
|
|
'<p>' +
|
|
|
|
e.value +
|
|
|
|
'</p>';
|
|
|
|
*/
|
|
|
|
|
2012-05-24 06:22:58 +00:00
|
|
|
var content = '<p>' + e.point.y + '</p>';
|
2012-05-22 23:16:42 +00:00
|
|
|
|
2012-05-23 22:37:28 +00:00
|
|
|
nv.tooltip.show([left, top], content, e.value < 0 ? 'n' : 's');
|
2012-05-22 23:16:42 +00:00
|
|
|
});
|
|
|
|
|
2012-05-24 06:22:58 +00:00
|
|
|
graph.dispatch.on('elementMouseout', function(e) {
|
2012-05-22 23:16:42 +00:00
|
|
|
nv.tooltip.cleanup();
|
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
|
|
graph.dispatch.on('elementClick', function(e) {
|
|
|
|
console.log("Bar Click",e);
|
|
|
|
});
|
|
|
|
|
|
|
|
graph.dispatch.on('chartClick', function(e) {
|
|
|
|
console.log("Chart Click",e);
|
|
|
|
});
|
|
|
|
|
|
|
|
graph.dispatch.on('chartClick', function(e) {
|
|
|
|
console.log('Click Switching to');
|
|
|
|
if (td === 0) {
|
|
|
|
d3.select("#test1")
|
|
|
|
.datum(testdata2)
|
|
|
|
.call(graph);
|
|
|
|
td = 1;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
d3.select("#test1")
|
|
|
|
.datum(testdata)
|
|
|
|
.call(graph);
|
|
|
|
td = 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
window.onresize = function() {
|
|
|
|
var width = nv.utils.windowSize().width - 40,
|
|
|
|
height = nv.utils.windowSize().height - 40;
|
|
|
|
|
|
|
|
graph
|
|
|
|
.width(width)
|
|
|
|
.height(height)
|
|
|
|
|
|
|
|
d3.select("#test1")
|
|
|
|
.attr('width', width)
|
|
|
|
.attr('height', height)
|
|
|
|
.call(graph);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Simple test data generators
|
|
|
|
|
|
|
|
function sinAndCos() {
|
|
|
|
var sin = [],
|
|
|
|
cos = [];
|
|
|
|
|
|
|
|
for (var i = 0; i < 100; i++) {
|
|
|
|
sin.push({x: i, y: Math.sin(i/10)});
|
|
|
|
cos.push({x: i, y: .5 * Math.cos(i/10)});
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
values: sin,
|
|
|
|
key: "Sine Wave",
|
|
|
|
color: "#ff7f0e"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
values: cos,
|
|
|
|
key: "Cosine Wave",
|
|
|
|
color: "#2ca02c"
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function sinData() {
|
|
|
|
var sin = [];
|
|
|
|
|
|
|
|
for (var i = 0; i < 100; i++) {
|
|
|
|
sin.push({x: i, y: Math.sin(i/10)});
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
values: sin,
|
|
|
|
key: "Sine Wave",
|
|
|
|
color: "#ff7f0e"
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|