Created
June 16, 2016 20:01
-
-
Save viebel/c4ae9d913d68a7f6d208428aa5edcbcf to your computer and use it in GitHub Desktop.
create a nvd3 chart
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
data = function() { | |
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' | |
} | |
]; | |
} | |
nv.addGraph(function() { | |
var chart = nv.models.lineChart() | |
.useInteractiveGuideline(true) | |
; | |
chart.xAxis | |
.axisLabel('Time (ms)') | |
.tickFormat(d3.format(',r')) | |
; | |
chart.yAxis | |
.axisLabel('Volt (v)') | |
.tickFormat(d3.format('.02f')) | |
; | |
d3.select('#chart svg') | |
.datum(data()) | |
.transition().duration(500) | |
.call(chart) | |
; | |
nv.utils.windowResize(chart.update); | |
return chart; | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment