Chartjs-Issue While Passing Dynamic Datas in React Chart Js 2

0👍

Try this:

`let reducedValue = props.expenses.reduce((acc, item) => {
    let index = acc.findIndex(accItem => moment(accItem.createdAt).format('MMM') === moment(item.createdAt).format('MMM'));
    if(index < 0){
        acc.push({...item});
    } else {
        acc[index].amount += item.amount;
    }
    return acc;
}, []);
let amount = reducedValue.map(item => item.amount);
let createdAt = reducedValue.map(item => moment(item.createdAt).format('MMM'));
`

Leave a comment