53 lines
1.1 KiB
JavaScript
53 lines
1.1 KiB
JavaScript
var btnStatus = document.getElementById('btnStatus');
|
|
var casespecializations = [];
|
|
|
|
window.addEventListener('load', async () => {
|
|
await $.ajax({
|
|
url: "/case/getspecializationcases",
|
|
type: "GET",
|
|
contentType: "json"
|
|
}).done((result) => {
|
|
casespecializations = result;
|
|
console.log(casespecializations);
|
|
});
|
|
})
|
|
|
|
var ctx = document.getElementById('myChart').getContext('2d');
|
|
var chart;
|
|
|
|
function drawStatusChart() {
|
|
var edStatus = [];
|
|
var edCount = [];
|
|
console.log(casespecializations)
|
|
casespecializations.forEach((item) => {
|
|
edStatus.push(item.name);
|
|
});
|
|
casespecializations.forEach((item) => {
|
|
edCount.push(item.count);
|
|
});
|
|
var statusData = {
|
|
labels: edStatus,
|
|
datasets: [{
|
|
data: edCount
|
|
}]
|
|
};
|
|
|
|
// Clear the previous chart if it exists
|
|
if (chart) {
|
|
chart.destroy();
|
|
}
|
|
|
|
chart = new Chart(ctx, {
|
|
type: 'pie',
|
|
data: statusData,
|
|
options: {
|
|
responsive: true
|
|
}
|
|
});
|
|
}
|
|
|
|
btnStatus.addEventListener('click', function () {
|
|
drawStatusChart();
|
|
});
|
|
|