You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
199 lines
3.9 KiB
HTML
199 lines
3.9 KiB
HTML
13 years ago
|
<!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/bar.js"></script>
|
||
|
<script>
|
||
|
|
||
|
var testdata = [
|
||
|
{
|
||
13 years ago
|
label: "One is a very long",
|
||
13 years ago
|
y: 5
|
||
|
},
|
||
|
{
|
||
13 years ago
|
label: "Two is also very long",
|
||
13 years ago
|
y: 2
|
||
13 years ago
|
},
|
||
|
{
|
||
|
label: "Three",
|
||
|
y: 9
|
||
|
},
|
||
|
{
|
||
|
label: "Four",
|
||
13 years ago
|
y: 7
|
||
13 years ago
|
},
|
||
|
{
|
||
|
label: "Five",
|
||
|
y: 4
|
||
13 years ago
|
},
|
||
|
{
|
||
|
label: "Six",
|
||
|
y: 3
|
||
13 years ago
|
}
|
||
|
];
|
||
|
|
||
13 years ago
|
|
||
|
var testdata2 = [
|
||
|
{
|
||
|
label: "One is a very long",
|
||
|
y: 1
|
||
|
},
|
||
|
{
|
||
|
label: "Two is also very long",
|
||
|
y: 12
|
||
|
},
|
||
|
{
|
||
|
label: "Three",
|
||
|
y: -9
|
||
|
},
|
||
|
{
|
||
|
label: "Four",
|
||
|
y: 4
|
||
|
},
|
||
|
{
|
||
|
label: "Five",
|
||
|
y: 6
|
||
|
}
|
||
|
];
|
||
|
|
||
|
var td = 0;
|
||
|
var a = (Math.random()*10)+1;
|
||
|
if (a > 5) td = 1;
|
||
|
|
||
13 years ago
|
//Format A
|
||
|
nv.addGraph({
|
||
|
generate: function() {
|
||
13 years ago
|
var width = nv.utils.windowSize().width - 40,
|
||
|
height = nv.utils.windowSize().height - 40;
|
||
|
|
||
13 years ago
|
var chart = nv.models.bar()
|
||
|
.width(width)
|
||
13 years ago
|
.height(height)
|
||
|
.labelField('label')
|
||
13 years ago
|
.dataField('y')
|
||
|
.showLabels(true)
|
||
|
.title("This is a sample chart title")
|
||
|
;
|
||
13 years ago
|
|
||
13 years ago
|
if (td === 0) {
|
||
|
d3.select("#test1")
|
||
|
.attr('width', width)
|
||
|
.attr('height', height)
|
||
|
.datum(testdata)
|
||
|
.call(chart);
|
||
|
} else {
|
||
|
d3.select("#test1")
|
||
|
.attr('width', width)
|
||
|
.attr('height', height)
|
||
|
.datum(testdata2)
|
||
|
.call(chart);
|
||
|
}
|
||
13 years ago
|
|
||
|
return chart;
|
||
|
},
|
||
|
callback: function(graph) {
|
||
13 years ago
|
|
||
|
graph.dispatch.on('tooltipShow', function(e) {
|
||
|
var offsetElement = document.getElementById("chart"),
|
||
|
left = e.pos[0],
|
||
|
top = e.pos[1];
|
||
|
|
||
|
var content = '<h3>' + e.label + '</h3>' +
|
||
|
'<p>' +
|
||
|
e.value +
|
||
|
'</p>';
|
||
|
|
||
|
nv.tooltip.show([left, top], content);
|
||
|
});
|
||
|
|
||
|
graph.dispatch.on('tooltipHide', function(e) {
|
||
|
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);
|
||
|
});
|
||
|
|
||
13 years ago
|
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;
|
||
|
}
|
||
|
});
|
||
|
|
||
|
|
||
13 years ago
|
window.onresize = function() {
|
||
13 years ago
|
var width = nv.utils.windowSize().width - 40,
|
||
|
height = nv.utils.windowSize().height - 40;
|
||
13 years ago
|
|
||
|
d3.select("#test1")
|
||
|
.attr('width', width)
|
||
|
.attr('height', height)
|
||
|
.call(
|
||
|
graph
|
||
13 years ago
|
.width(width)
|
||
|
.height(height)
|
||
13 years ago
|
)
|
||
13 years ago
|
};
|
||
13 years ago
|
}
|
||
|
});
|
||
|
|
||
|
/*
|
||
|
//Format B
|
||
|
nv.addGraph(function() {
|
||
|
var selection = d3.select("body")
|
||
|
.datum(irwinHallDistribution(10000, 10));
|
||
|
|
||
|
var chart = nv.models.histogram()
|
||
|
.bins(d3.scale.linear().ticks(20))
|
||
|
.tickFormat(d3.format(".02f"));
|
||
|
|
||
|
chart(selection);
|
||
|
|
||
|
return chart;
|
||
|
}, function(g) { console.log(g.width(), g.height()) })
|
||
|
|
||
|
//Format C
|
||
|
nv.addGraph(function() {
|
||
|
return nv.models.histogram()
|
||
|
.bins(d3.scale.linear().ticks(20))
|
||
|
.tickFormat(d3.format(".02f"))(
|
||
|
d3.select("body")
|
||
|
.datum(irwinHallDistribution(10000, 10))
|
||
|
);
|
||
|
}, function(g) { console.log(g.width(), g.height()) })
|
||
|
*/
|
||
|
|
||
|
|
||
|
|
||
|
</script>
|