Tengo un gráfico de líneas muy simple escrito usando NVD3.js. He escrito un redibujado simple basado en temporizador, sacado de ejemplos que he visto, pero me sale el errorGráfico de líneas NVD3 con datos en tiempo real
no detectada TypeError: No se puede leer la propiedad 'y' de la indefinida
La JS es
var data = [{
"key": "Long",
"values": getData()
}];
var chart;
nv.addGraph(function() {
chart = nv.models.cumulativeLineChart()
.x(function (d) { return d[0] })
.y(function (d) { return d[1]/100 })
.color(d3.scale.category10().range());
chart.xAxis
.tickFormat(function (d) {
return d3.time.format('%x')(new Date(d))
});
chart.yAxis
.tickFormat(d3.format(',.1%'));
d3.select('#chart svg')
.datum(data)
.transition().duration(500)
.call(chart);
nv.utils.windowResize(chart.update);
return chart;
});
function redraw() {
d3.select('#chart svg')
.datum(data)
.transition().duration(500)
.call(chart);
}
function getData() {
var arr = [];
var theDate = new Date(2012, 01, 01, 0, 0, 0, 0);
for (var x = 0; x < 30; x++) {
arr.push([theDate.getTime(), Math.random() * 10]);
theDate.setDate(theDate.getDate() + 1);
}
return arr;
}
setInterval(function() {
var long = data[0].values;
var next = new Date(long[long.length - 1][0]);
next.setMonth(next.getMonth() + 1)
long.shift();
long.push([next.getTime(), Math.random() * 100]);
redraw();
}, 1500);
¿Se puede agregar un jsfiddle que demuestre el problema? –
http://jsfiddle.net/khp9d/ –
@JaimalChohan ¿cómo solucionó esto? – Sajeetharan