1
votes

Hopefully a very simple question. I am displaying some data using DC.js and Crossfilter and need to plot annual totals based on the financial year range 1st April - 31st March, i.e. the 2015 total will cover the date range 1st April 2015 - 31st March 2016.

I have created a year dimension as below though this is based on each year covering 1st January - 31st December. I cannot find anything obvious through searching the D3/DC/Crossfilter documentation.

The date value in the csv file being imported is in the format YYYYMMDD.

var yearFormat = d3.time.format("%Y");

var yearDim = cf.dimension(function (d) {
    return yearFormat(d.myDateField);
}); 
1

1 Answers

4
votes

In this case you're making your dimension on solely the year part of the date. You would need to extend your yearFormat function to return the correct financial year number.

var yearFormat = function(date){
    if (date.getMonth < 3){
        return d3.time.format("%Y") - 1;
    } else {
        return d3.time.format("%Y");
    }
}