[Chartjs]-Chart JS – How to output JSON objects into PIE variant

3πŸ‘

βœ…

This will convert your data into the right format for ChartJS

function formatData(response) {
    let newFormat = {
        datasets: [{
            data: []
        }],
        labels: []
    };
    response.result.data.forEach(item => {
        newFormat.datasets[0].data.push(item.clicks);
        newFormat.labels.push(item.label);
    });
    return newFormat;
}

Leave a comment