Chart.js group data by month\year

Viewed 2431

I have such chart with some dates with days https://jsfiddle.net/wvtfe6sr/

  var ctx = $("#myChart");
  var myChart = new Chart(ctx, {
    type: 'line',
    data: {   
      labels: ['2019-04-10','2019-04-20','2019-05-11','2019-05-21','2019-06-12','2019-06-22'],   
      datasets: [{
        label: '#1',
        data: [
          {x:'2019-04-10', y:1},
          {x:'2019-04-20', y:2},
          {x:'2019-05-10', y:3},
          {x:'2019-05-20', y:4},
          {x:'2019-06-12', y:5},
          {x:'2019-06-22', y:6}
        ], 

      }]
    }
  });

Is possible to group this data by month\year using just chart functional? Like in excel

For example group by month will generate such chart https://jsfiddle.net/1o2xfa57/

With 3 months with sum of all days of each month

Also group by year will generate one dot with value 21

1 Answers

You will have to do the group by outside of Chart.js yourself before passing the data in

Related