I can't make a correct graph showing the data group by week (and different years).
pseudo SQL would give:
select sum ('task')
group by 'year', 'week' (and maybe later 'site')
My data looks more or less like this:
{ "date" : "20150427", "week" : 18, "site" : "a" "task" : 3, }
{ "date" : "20150427", "week" : 18, "site" : "b" "task" : 4, }
{ "date" : "20150427", "week" : 18, "site" : "c" "task" : 2, }
{ "date" : "20150427", "week" : 18, "site" : "d" "task" : 3, }
{ "date" : "20150428", "week" : 18, "site" : "a" "task" : 3, }
{ "date" : "20150428", "week" : 18, "site" : "b" "task" : 3, }
{ "date" : "20150429", "week" : 18, "site" : "c" "task" : 2, }
{ "date" : "20150429", "week" : 18, "site" : "d" "task" : 3, }
{ "date" : "20140512", "week" : 20, "site" : "d" "task" : 6, }
{ "date" : "20140512", "week" : 20, "site" : "a" "task" : 6, }
{ "date" : "20140513", "week" : 20, "site" : "b" "task" : 4, }
{ "date" : "20140513", "week" : 20, "site" : "c" "task" : 1, }
{ "date" : "20140519", "week" : 21, "site" : "b" "task" : 2, }
{ "date" : "20140519", "week" : 21, "site" : "c" "task" : 1, }
{ "date" : "20140519", "week" : 21, "site" : "d" "task" : 3, }
{ "date" : "20140519", "week" : 21, "site" : "a" "task" : 1, }
{ "date" : "20140520", "week" : 21, "site" : "b" "task" : 2, }
{ "date" : "20140520", "week" : 21, "site" : "c" "task" : 3, }
{ "date" : "20140520", "week" : 21, "site" : "d" "task" : 1, }
{ "date" : "20140520", "week" : 21, "site" : "a" "task" : 1, }
This is a sample of my data, it can have different years, sites or tasks
I tried this and it doesn't work, because the barChart cumulates the week of all years:
d3.json("/graph", function(dataJson) {
var dataTable = dc.dataTable("#dc-table-graph");
var barChart = dc.barChart("#chart-bar-ordersperweek");
var data = dataJson;
var dateFormat = d3.time.format("%Y%m%d");
data.forEach(function (d) { d.date = dateFormat.parse(d.date); });
//dimension
var dateDim = ndx.dimension(function (d) { return d.date; });
var weekDim = ndx.dimension(function(d) {return d.week;});
//group
var orderByWD = weekDim.group().reduceSum(function (d) { return d.task; });
barChart
.width(1000).height(250)
.dimension(weekDim)
.group(orderByWD)
.x(d3.scale.ordinal().domain(d3.range(minWeek.week-1,maxWeek.week+1)))
.xUnits(dc.units.ordinal)
.y(d3.scale.linear().domain([0, 6000]))
.margins({top: 20, right: 30, bottom: 50, left: 80})
.label(function(d) { return d.value})
;
dataTable.width(800).height(800)
.dimension(dateDim)
.group( function (d) { return 'Week ' + d.week} )
.size(5000)
.columns([
function (d) { var format = d3.format('02d');
return d.date.getFullYear() +'/'+ format(d.date.getMonth()+1) + '/' + format(d.date.getDate()); },
function (d) { return d.week; },
function (d) { return d.site; },
function (d) { return d.task; }
])
.sortBy( function (d) { return Number(d.date) + d.task; })
.order(d3.descending);
dataTable.on('renderlet', function(chart){
chart.selectAll('.dc-table-group').classed('info',true);
});
dc.renderAll();
My goal is to sum all task happened in same week and draw it to row chart and when I select a week that update the datatable with selected week.
In the dataTable how do I sum (cumulate) task by site grouped by week ?
Thanks for any help
EDIT i have add a jsfiddle https://jsfiddle.net/d4qsd8wh/