export function renderWorstSuppliersChart( chartData, containerId, tableContainerId, ) { // Pulizia del contenitore del grafico const chartContainer = document.querySelector(`#${containerId}`); if (chartContainer) { chartContainer.innerHTML = ""; } else { console.error(`Contenitore del grafico non trovato: #${containerId}`); return; } // Estrai i dati per il grafico const worstSuppliers = chartData || []; const suppliers = worstSuppliers.map((item) => item.supplier); const failPercentages = worstSuppliers.map((item) => item.failPercentage); // Configurazione del grafico a barre orizzontali const options = { series: [ { name: "Fail Percentage", data: failPercentages, }, ], chart: { type: "bar", height: 600, toolbar: { show: true, tools: { download: true, selection: false, zoom: false, zoomin: false, zoomout: false, pan: false, reset: false, }, }, }, plotOptions: { bar: { horizontal: true, barHeight: "80%", }, }, dataLabels: { enabled: true, formatter: function (val) { return val.toFixed(2) + "%"; }, }, xaxis: { categories: suppliers, title: { text: "Fail Percentage (%)", }, }, yaxis: { title: { text: "Supplier", }, }, colors: ["#FF4D4D"], fill: { opacity: 1, }, tooltip: { y: { formatter: function (val) { return val.toFixed(2) + "%"; }, }, }, }; // Render del grafico const chart = new ApexCharts(chartContainer, options); chart.render(); // Genera una tabella per i dati const tableHTML = `
| Supplier | Fail Percentage | Total Reports | Failed Reports |
|---|---|---|---|
| ${item.supplier} | ${item.failPercentage.toFixed(2)}% | ${item.totalReports} | ${item.failedReports} |