diff --git a/controllers/graficos.php b/controllers/graficos.php index 9256329..e766474 100644 --- a/controllers/graficos.php +++ b/controllers/graficos.php @@ -220,7 +220,7 @@ class Graficos{ $params[] = $filtros['fechaFin']; $types .= "ss"; } - $sql .= " GROUP BY ex.nombre_examen ORDER BY ex.nombre_examen"; + $sql .= " GROUP BY ex.id_examen, ex.nombre_examen ORDER BY ex.id_examen"; $query = $this->db->prepare($sql); if ($params) $query->bind_param($types, ...$params); diff --git a/js/funcionesGraficos.js b/js/funcionesGraficos.js index 5e60cb7..6553554 100644 --- a/js/funcionesGraficos.js +++ b/js/funcionesGraficos.js @@ -160,12 +160,25 @@ async function obtenerDatosEstados(filtros = {}) { } async function obtenerDatosExamenes(filtros = {}) { - const response = await fetch("../controllers/graficos.php", { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ tipoConsulta: "Examenes", ...filtros }), - }); - return await response.json(); + try { + const response = await fetch("../controllers/graficos.php", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + tipoConsulta: "Examenes", + ...filtros + }), + }); + const data = await response.json(); + if (!Array.isArray(data)) { + console.error("La respuesta del backend no es un array:", data); + return []; + } + return data; + } catch (error) { + console.error("Error al obtener datos de exámenes:", error); + return []; + } } async function obtenerDatosFechas(filtros = {}) {