Question

I am trying to use a csv data source with a column titled "Year" to produce a bar chart using dc.js to create a crossfilter-based dashboard. I can't see how to get the Year into a usable date format. Is there anyone that can help?

I am using dc.js 1.2 with d3.v3.min.js

I tried adapting the main example but have no idea what the "e" comes from:

var dateFormat = d3.time.format("%Y");
var numberFormat = d3.format(".2f");

         data.forEach(function(e) {
            e.dd = dateFormat.parse(e.Year);
         });

I also tried this:

var dateYear = new Date(d.Year, 0);// The required 0, is for January

The variable is declared as:

var yearDimension = data.dimension(function(d){ return d3.time.year(d.dd);});

And I also tried this to give up on the date format completely and using an ordinal scale:

.x(d3.scale.ordinal())
//.xUnits(d3.units.ordinal);

Declaring the variable as:

var yearDimension = data.dimension(function(d){ return d["Year"];});

and also

var yearDimension = data.dimension(function(d){ return (String(d["Year"]));});

but this set up generated this error:

Uncaught TypeError: Cannot read property 'ordinal' of undefined 

What am I doing wrong?

Was it helpful?

Solution

This was an error in declaring the csv file.

Problem solved here: https://github.com/NickQiZhu/dc.js/issues/127

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top