Ho un grafico a linee molto semplice scritto utilizzando NVD3.js. Ho scritto un ridisegno semplice basata su timer, tirato dagli esempi che ho visto, ma ho l'erroreGrafico a linee NVD3 con dati in tempo reale
Uncaught TypeError: Impossibile leggere la proprietà 'y' undefined
Il JS è
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);
si può aggiungere un jsfiddle che dimostra il problema? –
http://jsfiddle.net/khp9d/ –
@JaimalChohan come hai risolto questo problema? – Sajeetharan