Created
April 1, 2014 18:04
-
-
Save lemanchester/9919615 to your computer and use it in GitHub Desktop.
NVD3 - Cumulative Chart (getting wrong yScale)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<link href="../src/nv.d3.css" rel="stylesheet" type="text/css"> | |
<style> | |
body { | |
overflow-y:scroll; | |
} | |
text { | |
font: 12px sans-serif; | |
} | |
#chart svg { | |
height: 400px; | |
width: 400px; | |
} | |
</style> | |
<body> | |
<div id="chart" > | |
<svg /> | |
</div> | |
<script src="../lib/d3.v3.js"></script> | |
<script src="moment-with-langs.js"></script> | |
<script src="../nv.d3.js"></script> | |
<script src="../src/utils.js"></script> | |
<script src="../src/tooltip.js"></script> | |
<script src="../src/models/stackedArea.js"></script> | |
<script> | |
var data = [{ | |
key: "Page view", | |
values: [ | |
["2013-07-01 00:00:00", 1], | |
["2013-08-01 00:00:00", 17], | |
["2013-09-01 00:00:00", 5], | |
["2013-10-01 00:00:00", 13] | |
] | |
}]; | |
draw(); | |
function draw() { | |
nv.addGraph(function () { | |
var chart; | |
chart = nv.models.cumulativeLineChart() | |
.x(function(d) { return moment(d[0]) }) | |
.y(function(d) { return d[1] }) | |
.color(d3.scale.category10().range()) | |
.transitionDuration(300) | |
.showControls(false); | |
chart.xAxis | |
.tickFormat(function (d) { | |
return d3.time.format('%d/%m/%y')(new Date(d)) | |
}); | |
chart.xScale(d3.time.scale()); | |
d3.select('#chart svg') | |
.datum(data) | |
.call(chart); | |
nv.utils.windowResize(chart.update); | |
return chart; | |
}); | |
} | |
</script> |
I've discovery the problem, that Cumulative Line Chart it has to starts with 0 on the Y axis
var data = [{
key: "Page view",
values: [
["2013-06-01 00:00:00", 0],
["2013-07-01 00:00:00", 1],
["2013-08-01 00:00:00", 17],
["2013-09-01 00:00:00", 5],
["2013-10-01 00:00:00", 13]
]
}];
As you can see:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.evernote.com/shard/s253/sh/35928a9c-f5bb-4862-a227-f86423e6dd8a/8745a2c6cb5571002b7ec33b5386172a