[Chartjs]-Is it possible to merge duplicate labels (and their datas) into one column in Chart Js?

1👍

you can use reduce for this. May this helps you !

 var label = ['05/Feb/2019', '05/Feb/2019', '05/Feb/2019', '01/Feb/2019'];
    var value = ['2', '5', '7', '4'];

    var obj = label.reduce(function(a, b, i) {
        if(!a.hasOwnProperty(b)) {
            a[b] = 0;
        }
        console.log(a);
        a[b] += Number(value[i]);
         return a;
    },{});

    var lab = Object.keys(obj);
    var val = Object.values(obj);

Leave a comment