Yosi
Yosi

Reputation: 2966

Adding records to crossfilter dosen't update the dc.js lineChart group

I am using dc.js and crossfilter in my application. In my code, I listen for event when data is coming (for example from websocket) and add the data to my crossfilter instance and then I call dc.redrawAll();

I have seen that the dc lineChart dosen't update it's grouping values.

var instance = crossfilter();

function onData(data) {
  instance.add(data);

  // -- code to update the x/y axis domains

  dc.redrawAll();
}

function drawLineChart() {
  var dimension = instance.dimension(function(){ .. });

  // => WHEN DATA IS ADDED (onData)
  // THE GROUPING DOSEN'T UPDATE
  var grouping = dimension.group().reduceCount();

  // initializing the line chart
  var lineChart = dc.lineChart() ....;

  lineChart.dimension(dimension).group(grouping);
}

What should I do to update the grouping?

Upvotes: 2

Views: 2674

Answers (2)

vopilif
vopilif

Reputation: 1211

You don't mention what your data is, but I assume that it's a single object rather than an array of data objects. You need to pass an array. If you pass just a single data object it seems to silently fail as you observed.

instance.add([data]); // `[data]` instead of `data`

Upvotes: 0

leoh
leoh

Reputation: 10608

dimension and group should be automatically updated. See this example: http://jsfiddle.net/yHmkc/1/

Where the data added and chart updated 1 sec later

setTimeout(function () {
    cf.add([{
        "key": "KEY-6",
        "state": "MD",
        "topics": ["Science"],
        "date": new Date("10/09/2012")
    }]);
    dc.redrawAll();
}, 1000);

Upvotes: 5

Related Questions