I am pulling a JSON response into a ChartJS pie chart. Reading the docs it says that it needs to use datasets as:
datasets: [{
data: [10, 20, 30]
}],
For my use case, the JSON is pulling in as:
{
"action": "data_link_referer",
"result": {
"url_ending": "0",
"data": [{
"label": "Link1",
"clicks": 3
}, {
"label": "Link2",
"clicks": 3
}, {
"label": "Link3",
"clicks": 2
}]
}
}
Inside the chart function I am pulling out the [data]. I would like to set the clicks as the value.
function drawChartPie(jsonObj) {
var ctx = document.getElementById("myChartPie");
var data = jsonObj["result"]["data"];
var myPieChart = new Chart(ctx,{
type: 'pie',
data: {
labels: data,
datasets: [{
label: 'Referers',
data: data,
}]
},
});
}