JavaScript
nv.addGraph(function() {
var chart = nv.models.lineChart()
.margin({top: 30, right: 60, bottom: 50, left: 70})
.x(function(d,i) { return i })
.y(function(d) { return d[1] })
.color(d3.scale.category10().range())
;
var data = SampleData();
chart.xAxis
.showMaxMin(false)
.tickFormat(function(d) {
var dx = data[0].values[d] && data[0].values[d][0] || 0;
return d3.time.format('%x')(new Date(dx))
});
chart.yAxis
.tickFormat(d3.format(',f'));
d3.select('#chart svg')
.datum(data)
.transition().duration(500)
.call(chart)
;
nv.utils.windowResize(chart.update);
return chart;
});
function SampleData(){
return [{
"key" : "isBaking",
"color": "#ccf",
"values" : [ [ 1136005200000 , 0] , [ 1138683600000 , 0], [ 1141102800000 , 0],
[ 1141102800000 , 100] , [ 1143781200000 , 100] , [ 1143781200000 , 0], [ 1146369600000 , 0] ,
[ 1149048000000 , 0] , [ 1151640000000 , 0] , [ 1154318400000 , 0] ,
[ 1156996800000 , 100] , [ 1159588800000 , 100] , [ 1162270800000 , 0] ,
[ 1164862800000 , 0] , [ 1167541200000 , 100] , [ 1170219600000 , 100] ,
[ 1172638800000 , 100] , [ 1175313600000 , 0] , [ 1177905600000 , 0] ,
[ 1180584000000 , 100] , [ 1183176000000 , 100] , [ 1185854400000 , 0] ,
[ 1188532800000 , 100] , [ 1191124800000 , 100] , [ 1193803200000 , 100] ,
[ 1196398800000 , 100] , [ 1199077200000 , 0] , [ 1201755600000 , 100] ,
[ 1204261200000 , 100] , [ 1206936000000 , 0] , [ 1209528000000 , 0] ,
[ 1212206400000 , 0] , [ 1214798400000 , 0] , [ 1217476800000 , 0] ,
[ 1220155200000 , 0] , [ 1222747200000 , 0] , [ 1225425600000 , 0] ]
},
{
"key" : "Temperature",
"color" : "#333",
"values" : [[ 1136005200000 , 71.89] , [ 1138683600000 , 75.51] ,
[ 1141102800000 , 68.49] , [ 1143781200000 , 62.72] , [ 1146369600000 , 70.39] ,
[ 1149048000000 , 59.77] , [ 1151640000000 , 57.27] , [...