PMSI-AlignAlytics / dimple

An object-oriented API for business analytics
Other
2.73k stars 556 forks source link

Error: Invalid value for <rect> attribute x="NaN" when redrawing bar chart with some data points removed #214

Open stanislawosinski opened 8 years ago

stanislawosinski commented 8 years ago

The following code with dimple 2.1.6:

var svg = dimple.newSvg("body", 1200, 800);

var data = [
  {x: "a", y: 1},
  {x: "b", y: 2}
];

// Create a new chart object based on this data and svg
var myChart = new dimple.chart(svg, data);
myChart.addCategoryAxis("x", "x");
myChart.addMeasureAxis("y", "y");
myChart.addSeries(null, dimple.plot.bar);
myChart.draw();
setTimeout(function () {
  myChart.data = data.slice(0, 1);
  myChart.draw(); // throws errors
}, 1000);

throws Error: Invalid value for <rect> attribute x="NaN" on the second call to draw(). I'm fairly new to dimple -- is my code breaking some assumption and thus causes dimple to throw errors?

jo-me commented 7 years ago

Sam issue here in most recent version of dimple. I'm getting a stream of data points via socketIO and want to plot the last 100 only. So as soon as my data array has >100 entries I do a dataArray.shift() to remove the oldest element.

The chart throws the errors above and messes up its display. Only the right half of the chart seems to be updating, the left half is frozen.