Reputation: 51
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?
Upvotes: 0
Views: 1919
Reputation: 51
This was an error in declaring the csv file.
Problem solved here: https://github.com/NickQiZhu/dc.js/issues/127
Upvotes: 0