I'm trying to render a bar chart using the dc.js library. My csv dataset is formatted like so:
q, year, category, subcategory, total,
q1, 2010, x, xa, 200
q2, 2010, y, yb, 100
q3, 2010, x, xa, 300
q4, 2010, z, zb, 45
q1, 2010, x, xa, 80
q2, 2010, y, yb, 200
q3, 2010, x, xc, 301
q4, 2010, z, za, 205
q1, 2011, x, xa, 80
q2, 2011, y, yb, 200
q3, 2011, x, xc, 301
q4, 2011, z, za, 205
So far, I'm able to get a bar chart, but the actual data isn't rendered to the chart, also the scaling on the x-axis is off as well, since it should be according to years. I'm having difficulty appending the data to the graph. This is all that I've been able to get
I'm loading in the data through d3.csv as follows:
d3.csv("records.csv", function(csv) {
var data = crossfilter(csv);
var fiscalyear = data.dimension(function (d) {
return d.year;
});
var spendGroup = fiscalyear.group().reduce(
function(p,v) {
return p.total += v.total;
},
function(p,v) {
return p.total -= v.total;
},
function() {
return {totalSpend:0};
}
);
fiscalyearchart.width(600)
.height(300)
.margins({top: 10, right: 50, bottom: 30, left: 60})
.dimension(fiscalyear)
.group(spendGroup)
.x(d3.scale.linear().domain([2010,2013]))
.renderHorizontalGridLines(true)
.centerBar(true)
.elasticY(true)
.brushOn(true);
dc.renderAll();
});