I have a created an intial dc.js stacked area line chart from time series data coming in from a local database. All of the calculations are handled by the database server, data is grabbed in time intervals (several minutes to several hours). The crossfilter dimension used is date (given in millisecond epoch time) and includes 2 groups to be graphed together on one chart. The values in these 2 groups is averaged over the time intervals chosen, again this is done by the db server and I would very much like to avoid loading the entire data set into the script.
The initial chart renders and works just fine, but in my chart.on('zoomed', function(c, f) {..}) I parse the database again for a new, more accurate set of data.
i.e. zooming in on the chart selects data from a smaller time interval and zooming out selects data from a larger time interval.
I understand the the old data needs to be removed from the crossfilter and new data needs to added to it, source from this thread. However, when I implement that into my chart.on('zoomed', function(c,f) {..}), after the first zoom it returns a TypeError: group is undefined.
I don't understand where this error is coming from, chart.group(..) is defined when the page first loads. Here is my function,
.on('zoomed', function(chart, filter) {
var nextLower = stackedLine.x().domain()[0];
var nextUpper = stackedLine.x().domain()[1];
$.getJSON('/_try_db', {
lower : Date.parse(nextLower),
upper : Date.parse(nextUpper)
}, function(data) {
stackedLine.expireCache()
.stack()
.x(d3.time.scale().domain([Date.parse(nextLower), Date.parse(nextUpper)]))
;
var new_arr = [];
$.each(data.result, function() {
new_arr.push({
"timestamp" : ($.parseJSON(this)).timestamp,
"running" : ($.parseJSON(this)).running,
"waiting" : ($.parseJSON(this)).waiting
});
});
dd.filter(null);
ndx.remove();
ndx.add(new_arr);
dc.redrawAll();
});