diff --git a/recruitment/static/dashboard/recruitmentChart.js b/recruitment/static/dashboard/recruitmentChart.js index b47bf9d26..dfc8d1169 100644 --- a/recruitment/static/dashboard/recruitmentChart.js +++ b/recruitment/static/dashboard/recruitmentChart.js @@ -1,53 +1,84 @@ $(document).ready(function () { - function recruitmentChart(dataSet, labels) { - const data = { - labels: labels, - datasets: dataSet, - }; - // Create chart using the Chart.js library - window['myChart'] = {} - const ctx = document.getElementById("recruitmentChart1").getContext("2d"); - myChart = new Chart(ctx, { - type: 'bar', - data: data, - options: { - onClick: (e, activeEls) => { - let datasetIndex = activeEls[0].datasetIndex; - let dataIndex = activeEls[0].index; - let datasetLabel = e.chart.data.datasets[datasetIndex].label; - let value = e.chart.data.datasets[datasetIndex].data[dataIndex]; - let label = e.chart.data.labels[dataIndex]; - localStorage.removeItem("savedFilters"); - window.location.href = "/recruitment/candidate-view" +"?recruitment="+datasetLabel+"&stage_id__stage_type="+ label.toLowerCase() - } - }, - }); - } - $.ajax({ - url: "/recruitment/dashboard-pipeline", - type: "GET", - success: function (response) { - // Code to handle the response - // response = {'dataSet': [{'label': 'Odoo developer 2023-03-30', 'data': [3, 0, 5, 3]}, {'label': 'React developer 2023-03-31', 'data': [0, 1, 1, 0]}, {'label': 'Content Writer 2023-04-01', 'data': [1, 0, 0, 0]}], 'labels': ['Initial', 'Test', 'Interview', 'Hired']} - dataSet = response.dataSet; - labels = response.labels; - recruitmentChart(dataSet, labels); - }, - }); + function isChartEmpty(chartData) { + if (!chartData) { + return true; + } + for (let i = 0; i < chartData.length; i++) { + if (chartData[i] && chartData[i].data) { + const hasNonZeroValues = chartData[i].data.some((value) => value !== 0); + if (hasNonZeroValues) { + return false; + } + } + } + return true; + } - $('#chart1').click(function (e) { - var chartType = myChart.config.type - if (chartType === 'line') { - chartType = 'bar'; - } else if(chartType==='bar') { - chartType = 'doughnut'; - } else if(chartType==='doughnut'){ - chartType = 'pie' - }else if(chartType==='pie'){ - chartType = 'line' - } - myChart.config.type = chartType; - myChart.update(); - }); - + function recruitmentChart(dataSet, labels) { + const data = { + labels: labels, + datasets: dataSet, + }; + // Create chart using the Chart.js library + window["myChart"] = {}; + const ctx = document.getElementById("recruitmentChart1").getContext("2d"); + myChart = new Chart(ctx, { + type: "bar", + data: data, + options: { + onClick: (e, activeEls) => { + let datasetIndex = activeEls[0].datasetIndex; + let dataIndex = activeEls[0].index; + let datasetLabel = e.chart.data.datasets[datasetIndex].label; + let value = e.chart.data.datasets[datasetIndex].data[dataIndex]; + let label = e.chart.data.labels[dataIndex]; + localStorage.removeItem("savedFilters"); + window.location.href = + "/recruitment/candidate-view" + + "?recruitment=" + + datasetLabel + + "&stage_id__stage_type=" + + label.toLowerCase(); + }, + }, + }); + } + $.ajax({ + url: "/recruitment/dashboard-pipeline", + type: "GET", + success: function (response) { + // Code to handle the response + dataSet = response.dataSet; + labels = response.labels; + if (isChartEmpty(dataSet)) { + $("#recruitmentChart1") + .parent() + .html( + `
+