Counting "dates" in bar graph

So here’s what I’m trying to do …

I have a list with ‘tasks’. I only collect the last 21 days of tasks. In my bar graph I have one access being the person who modified the task, in the other axis the total number of tasks they’ve modified in the last 21 days. I would like to break that total down by “time” periods…

for example - i’ve modified 12 tasks over the last 21 days. 3 in the last 2 days, 6 in the 3rd through 7th day and the remained in days 8-21…

how would i go about doing that grouping?

right now i have it working by “task status” … but I really need to break it down by date…Image 1

Dear @evarzea,
Can you please export the data for us, so we can take a look at it ourselves? All you need to do, is process the data as you normally do and press Export data in the bottom:


But this will replace grouping by status. Do you want to display only completed tasks or all of them?

absolutely… data.txt (33.8 KB)

I’m thinking… i may also have to create a “special” date field that will take the “modified date” and strip the time to make it easier… so it will literally be just mo/da/year… or something like that…

Dear Evarzea,
Here will be code for grouping items by date. Currently, it doesn't take month into account, I am afraid that will create too many series, but if you'll want to include it - it can be done.

First, you'll need to replace handlers.finish = function(data, logger) {...} in Data Source -> Advanced with the following code:

handlers.finish = function(data, logger) {
  data.groups = [];
  var groupNames = [];

  function assignToGroup(groupName, item){
    for(var i = 0; i < data.groups.length; i++){
      if(data.groups[i].value == groupName){
        data.groups[i].items.push(item);
        return;
      }
    }

    var group = {};
    group.field = 'Days';
    group.value = groupName;
    group.hasSubgroups = false;
    group.aggregates = {};

    group.items = [];
    group.items.push(item);

    data.groups.push(group);
    groupNames.push(groupName);
  }
  
  for (var i = 0; i < data.items.length; i++){
    var modDate = new Date(data.items[i].Modified);
    var groupName = '';
    if(modDate.getDate() < 6){
        groupName = 'Days 1-5';
        assignToGroup(groupName, data.items[i]);
    } else if(modDate.getDate() < 12){
        groupName = 'Days 6-11';
        assignToGroup(groupName, data.items[i]);
    } else if(modDate.getDate() < 18){
        groupName = 'Days 11-17';
        assignToGroup(groupName, data.items[i]);
    } else if(modDate.getDate() < 24){
        groupName = 'Days 18-24';
        assignToGroup(groupName, data.items[i]);
    } else {
        groupName = 'Days 25-31';
        assignToGroup(groupName, data.items[i]);
    }
  }
   
  logger.debug('Data is processed: ', data);
  return true;
}

Then, add this code to Dashboard -> Advanced and replace everything there:

var handlers = {};
handlers.preRender = function(config, logger) {
  logger.debug('Configuration: ', config);
  var ordering = ['Days 1-5', 'Days 6-11', 'Days 11-17', 'Days 18-24', 'Days 25-31'];
 	config.series.sort(function(a, b) { 
    return ordering.indexOf(a.name) > ordering.indexOf(b.name); 
  });
  return true;
}

Here's the result that I get with your data:

thank you so much… i don’t think i explained what i wanted very well… but your code helped me get where I needed to… so here’s what I ended up doing:

handlers.finish = function(data, logger) {
  data.groups = [];
  var groupNames = [];

  function assignToGroup(groupName, item){
    for(var i = 0; i < data.groups.length; i++){
      if(data.groups[i].value == groupName){
        data.groups[i].items.push(item);
        return;
      }
    }

    var group = {};
    group.field = 'Days';
    group.value = groupName;
    group.hasSubgroups = false;
    group.aggregates = {};

    group.items = [];
    group.items.push(item);

    data.groups.push(group);
    groupNames.push(groupName);
  }
  
  var today=new Date();
  var myToday = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 0, 0, 0);
  var twoDaysAgo = new Date(today.getFullYear(), today.getMonth(), today.getDate()-2, 0, 0, 0);
  var sevenDaysAgo = new Date(today.getFullYear(), today.getMonth(), today.getDate()-7, 0, 0, 0);
  
  for (var i = 0; i < data.items.length; i++){
    var modDate = new Date(data.items[i].Modified);
    var modDateGeneral = new Date(modDate.getFullYear(), modDate.getMonth(), modDate.getDate(), 0, 0, 0);
    var groupName = '';
    if(modDateGeneral > twoDaysAgo){
        groupName = 'Last 2 Days';
        assignToGroup(groupName, data.items[i]);
    } else if(modDateGeneral > sevenDaysAgo){
        groupName = 'Days 3-7';
        assignToGroup(groupName, data.items[i]);
    } else {
        groupName = 'Days 8-21';
        assignToGroup(groupName, data.items[i]);
    }
  }
   
  logger.debug('Data is processed: ', data);
  return true;
}

and

  var ordering = ['Last 2 Days', 'Days 3-7', 'Days 8-21'];
 	config.series.sort(function(a, b) { 
    return ordering.indexOf(a.name) > ordering.indexOf(b.name); 
  });

works like a charm! your support is always awesome and welcome…

thank you!

Dear @evarzea,
Glad to hear that! I’ve slightly edited your post, so the formatting is applied to code - in case somebody needs to use it as well. If you’ll need anything, just let us know - we’ll be glad to help!

1 Like