Skip to content

Instantly share code, notes, and snippets.

@viebel
Created June 16, 2016 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viebel/c4ae9d913d68a7f6d208428aa5edcbcf to your computer and use it in GitHub Desktop.
Save viebel/c4ae9d913d68a7f6d208428aa5edcbcf to your computer and use it in GitHub Desktop.
create a nvd3 chart
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