I need to replicate several graphs showing the results of the database, however I would like to make dynamic without having to make a function for each bank information because there are many lines.
JavaScript chart code:
function radarArea() {
var options = {
responsive:true
};
var data = {
labels: ["1S Seiri", "2S Seiton", "3S Seisou", "4S Seiketsu", "5S Shitsuke"],
datasets: [
{
label: "Quartil Anterior",
fillColor: "rgba(255,0,0,0.2)",
strokeColor: "rgba(255,0,0,1)",
pointColor: "rgba(255,0,0,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#FFFF00",
pointHighlightStroke: "rgba(220,220,220,1)",
data: [0,0,0,0,0]
},
{
label: "Quartil Atual",
fillColor: "rgba(151,187,205,0.2)",
strokeColor: "rgba(151,187,205,1)",
pointColor: "rgba(151,187,205,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#FFFF00",
pointHighlightStroke: "rgba(151,187,205,1)",
data: [<?php echo round($row1[0]); ?>, <?php echo round($row2[0]); ?>, <?php echo round($row3[0]); ?>, <?php echo round($row4[0]); ?>, <?php echo round($row5[0]); ?>]
}
]
};
var ctx = document.getElementById("ChartRadar").getContext("2d");
var grafico = new Chart(ctx).Radar(data, options);
legend(document.getElementById("radarLegend"), data);
}
The PHP query:
$seiri = mysql_query("select case when left(sum(total),4)/count(total) is null then 0 else left(sum(total),4)/count(total) end as s1 from mobile.auditoria a inner join mobile.seiri b on a.id = b.id where data >= '$inicio 00:00:00' and data <= '$fim 23:59:59' and setor = '$setor'");
$row1 = mysql_fetch_row($seiri);
$seisou = mysql_query("select case when left(sum(total),4)/count(total) is null then 0 else left(sum(total),4)/count(total) end as s2 from mobile.auditoria a inner join mobile.seiton b on a.id = b.id where data >= '$inicio 00:00:00' and data <= '$fim 23:59:59' and setor = '$setor'");
$row2 = mysql_fetch_row($seisou);
$seiton = mysql_query("select case when left(sum(total),4)/count(total) is null then 0 else left(sum(total),4)/count(total) end as s3 from mobile.auditoria a inner join mobile.seisou b on a.id = b.id where data >= '$inicio 00:00:00' and data <= '$fim 23:59:59' and setor = '$setor'");
$row3 = mysql_fetch_row($seiton);
$seiketsu = mysql_query("select case when left(sum(total),4)/count(total) is null then 0 else left(sum(total),4)/count(total) end as s4 from mobile.auditoria a inner join mobile.seiketsu b on a.id = b.id where data >= '$inicio 00:00:00' and data <= '$fim 23:59:59' and setor = '$setor'");
$row4 = mysql_fetch_row($seiketsu);
$shitsuk = mysql_query("select case when left(sum(total),4)/count(total) is null then 0 else left(sum(total),4)/count(total) end as s5 from mobile.auditoria a inner join mobile.shitsuk b on a.id = b.id where data >= '$inicio 00:00:00' and data <= '$fim 23:59:59' and setor = '$setor'");
$row5 = mysql_fetch_row($shitsuk);