nvd3/examples/sparklinePlus.html

68 lines
1.1 KiB
HTML

<!DOCTYPE html>
<meta charset="utf-8">
<link href="../src/nv.d3.css" rel="stylesheet" type="text/css">
<style>
#chart1 {
width: 500px;
height: 50px;
font-size: 14px;
margin-top: -6px;
}
h2, p {
float: left;
}
</style>
<body>
<h2>SparklinePlus:</h2>
<p><svg id="chart1" class="sparkline"></svg></p>
<script src="../lib/d3.v2.js"></script>
<script src="../nv.d3.js"></script>
<script src="../src/utils.js"></script>
<script src="../src/models/sparkline.js"></script>
<script src="../src/models/sparklinePlus.js"></script>
<script>
nv.addGraph(function() {
var data = sine();
var chart = nv.models.sparklinePlus()
chart
.margin({left:70})
.x(function(d,i) { return i })
.xTickFormat(function(d) {
return d3.time.format('%x')(new Date(data[d].x))
})
d3.select("#chart1")
.datum(data)
.transition().duration(250)
.call(chart);
return chart;
});
var now =+new Date();
function sine() {
var sin = [];
nv.log(now);
for (var i = 0; i < 100; i++) {
sin.push({x: now + i * 1000 * 60 * 60 * 24, y: Math.sin(i/10)});
}
return sin;
}
</script>