|
|
|
var urlParams = new URLSearchParams(window.location.search); |
|
var data = JSON.parse(decodeURIComponent(urlParams.get('data'))); |
|
var backgroundColor = JSON.parse(decodeURIComponent(urlParams.get('backgroundColor'))); |
|
var borderColor = JSON.parse(decodeURIComponent(urlParams.get('borderColor'))); |
|
var labels = JSON.parse(decodeURIComponent(urlParams.get('labels'))); |
|
|
|
|
|
function initializeOrUpdateChart(data, backgroundColor, borderColor, labels) { |
|
|
|
if (window.myChart) { |
|
|
|
window.myChart.data.datasets[0].data = data; |
|
window.myChart.data.datasets[0].backgroundColor = backgroundColor; |
|
window.myChart.data.datasets[0].borderColor = borderColor; |
|
window.myChart.data.labels = labels; |
|
window.myChart.update(); |
|
} else { |
|
|
|
var ctx = document.getElementById('bestSellers').getContext('2d'); |
|
window.myChart = new Chart(ctx, { |
|
type: 'doughnut', |
|
data: { |
|
datasets: [{ |
|
data: data, |
|
backgroundColor: backgroundColor, |
|
borderColor: borderColor |
|
}], |
|
labels: labels |
|
}, |
|
options: { |
|
responsive: true, |
|
cutoutPercentage: 80, |
|
legend: { |
|
display: false |
|
}, |
|
animation: { |
|
animateScale: true, |
|
animateRotate: true |
|
}, |
|
plugins: { |
|
datalabels: { |
|
display: false, |
|
align: 'center', |
|
anchor: 'center' |
|
} |
|
} |
|
} |
|
}); |
|
} |
|
} |
|
|
|
|
|
initializeOrUpdateChart(data, backgroundColor, borderColor, labels); |
|
|