Case_accounting/CaseAccounting/CaseAccountingProviderView/wwwroot/js/diagram/diagram.js

53 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-05-20 05:04:42 +04:00
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();
});