Ketan
Ketan

Reputation: 5891

Simple line chart in DC and CrossFilter

I have some data like this

var data =  [{date:'2013/01/01', claimNo:1},
             {date:'2013/01/01', claimNo:2},
             {date:'2013/01/02', claimNo:3}]

I want to plot a line chart in DC so that the days are on the X-Axis and the total # of claims are on the Y-Axis.

I have code like this

var ndx = crossfilter(data);
 data.forEach(function (e) {
    e.dd = dateFormat.parse(e.dd);
    e.month = d3.time.month(e.dd); 
});
var dateDim = ndx.dimension(function (d) {
    return d.dd;
});
var datesClaimsGroup = dateDim.group();
var claimsLineChart = dc.lineChart("#claims-line-chart");

 claimsLineChart
    .width(200)
    .height(40)
    .renderArea(true)
    .margins({ top: 0, left: -1, right: 2, bottom: 1 })
    .group(datesClaimsGroup)
    .dimension(dateDim)
    .x(d3.time.scale().domain([data[0].dd, data[data.length - 1].dd]))
    .title(function (d) {
        return d.value;
    });

The chart is plotted but the values in Y-Axis are the date occurance counts and not the claim counts. I know I am supposed to use a function to count the claims but I am not getting there.

Upvotes: 1

Views: 2071

Answers (1)

JRideout
JRideout

Reputation: 1635

For datesClaimsGroup you need to provide a reduce function to count the claims. Otherwise just .group() will default to an identity count reduce function as you observed.

var datesClaimsGroup = dateDim.group().reduceSum(...) 

or

var datesClaimsGroup = dateDim.group().reduce(...) 

Upvotes: 1

Related Questions