2012-04-05 05:24:39 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
|
2012-07-13 19:25:19 +00:00
|
|
|
<link href="../src/nv.d3.css" rel="stylesheet" type="text/css">
|
2012-04-05 05:24:39 +00:00
|
|
|
|
|
|
|
<style>
|
|
|
|
|
|
|
|
body {
|
|
|
|
overflow-y:scroll;
|
|
|
|
}
|
|
|
|
|
|
|
|
text {
|
|
|
|
font: 12px sans-serif;
|
|
|
|
}
|
|
|
|
|
2012-06-15 16:47:47 +00:00
|
|
|
svg {
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
|
|
|
|
#chart1 svg {
|
2012-04-05 05:24:39 +00:00
|
|
|
height: 500px;
|
|
|
|
min-width: 100px;
|
|
|
|
min-height: 100px;
|
|
|
|
/*
|
2012-06-15 16:47:47 +00:00
|
|
|
margin: 50px;
|
2012-04-05 05:24:39 +00:00
|
|
|
Minimum height and width is a good idea to prevent negative SVG dimensions...
|
|
|
|
For example width should be =< margin.left + margin.right + 1,
|
|
|
|
of course 1 pixel for the entire chart would not be very useful, BUT should not have errors
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
</style>
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<div id="chart1">
|
2012-06-15 16:47:47 +00:00
|
|
|
<svg style="height: 500px;"></svg>
|
2012-04-05 05:24:39 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<script src="../lib/d3.v2.js"></script>
|
|
|
|
<script src="../nv.d3.js"></script>
|
2012-05-07 12:53:51 +00:00
|
|
|
<script src="../src/tooltip.js"></script>
|
2012-06-15 16:47:47 +00:00
|
|
|
<script src="../src/utils.js"></script>
|
2012-04-05 05:24:39 +00:00
|
|
|
<script src="../src/models/legend.js"></script>
|
2012-05-17 06:04:33 +00:00
|
|
|
<script src="../src/models/axis.js"></script>
|
2012-06-15 16:47:47 +00:00
|
|
|
<script src="../src/models/scatter.js"></script>
|
2012-04-05 05:24:39 +00:00
|
|
|
<script src="../src/models/line.js"></script>
|
2012-06-15 16:47:47 +00:00
|
|
|
<script src="../src/models/lineChart.js"></script>
|
2012-04-05 05:24:39 +00:00
|
|
|
<script>
|
|
|
|
|
|
|
|
|
2012-06-15 16:47:47 +00:00
|
|
|
// Wrapping in nv.addGraph allows for '0 timeout render', stors rendered charts in nv.graphs, and may do more in the future... it's NOT required
|
2012-07-16 21:00:41 +00:00
|
|
|
nv.addGraph(function() {
|
2012-06-15 16:47:47 +00:00
|
|
|
var chart = nv.models.lineChart();
|
|
|
|
|
|
|
|
chart.xAxis // chart sub-models (ie. xAxis, yAxis, etc) when accessed directly, return themselves, not the partent chart, so need to chain separately
|
2012-07-16 19:27:15 +00:00
|
|
|
.tickFormat(d3.format(',.1f'));
|
2012-06-15 16:47:47 +00:00
|
|
|
|
|
|
|
chart.yAxis
|
|
|
|
.axisLabel('Voltage (v)')
|
|
|
|
.tickFormat(d3.format(',.2f'));
|
|
|
|
|
|
|
|
d3.select('#chart1 svg')
|
2012-08-22 18:29:42 +00:00
|
|
|
.datum([])
|
|
|
|
//.datum(sinAndCos())
|
2012-06-15 16:47:47 +00:00
|
|
|
.transition().duration(500)
|
|
|
|
.call(chart);
|
2012-04-05 05:24:39 +00:00
|
|
|
|
2012-06-15 16:47:47 +00:00
|
|
|
//TODO: Figure out a good way to do this automatically
|
|
|
|
nv.utils.windowResize(chart.update);
|
|
|
|
//nv.utils.windowResize(function() { d3.select('#chart1 svg').call(chart) });
|
2012-04-05 05:24:39 +00:00
|
|
|
|
2012-06-15 16:47:47 +00:00
|
|
|
return chart;
|
|
|
|
});
|
2012-04-05 05:24:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function sinAndCos() {
|
|
|
|
var sin = [],
|
2012-06-15 16:47:47 +00:00
|
|
|
cos = [];
|
2012-04-05 05:24:39 +00:00
|
|
|
|
|
|
|
for (var i = 0; i < 100; i++) {
|
2012-07-16 19:27:15 +00:00
|
|
|
sin.push({x: i, y: i % 10 == 5 ? null : Math.sin(i/10) }); //the nulls are to show how defined works
|
2012-06-15 16:47:47 +00:00
|
|
|
cos.push({x: i, y: .5 * Math.cos(i/10)});
|
2012-04-05 05:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
{
|
2012-07-19 06:15:53 +00:00
|
|
|
area: true,
|
2012-04-05 05:24:39 +00:00
|
|
|
values: sin,
|
|
|
|
key: "Sine Wave",
|
|
|
|
color: "#ff7f0e"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
values: cos,
|
|
|
|
key: "Cosine Wave",
|
|
|
|
color: "#2ca02c"
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
</script>
|