Gráficos com PHP e ChartsJS
Galera,
Tenho um questionário com 10 perguntas. todas essas perguntas tem valor de 0 à 5.
Preciso analisar quantas vezes aparecem a nota 0, 1, 2, 3,4 e 5 em cada pergunta, no caso eu teria que fazer 5 consultas por pergunta, certo ?
Estou criando gráficos para essas perguntas, como são 10 perguntas, pensei em criar um while.
Vou postar o código para ver se podem me ajudar.
HTML
<!doctype html>
<html>
<head>
<title>Bar Chart</title>
<script src="Chart.js-master/Chart.js"></script>
</head>
<body>
<div style="width: 50%">
<canvas id="pergunta1" height="450" width="600"></canvas>
</div>
<script>
var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
var barChartData = {labels : ["0","1","2","3","4","5"],
datasets : [
{
label: "Dados primários",
fillColor: "rgba(220,220,220,0.2)",
strokeColor: "rgba(220,220,220,1)",
pointColor: "rgba(220,220,220,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
<?php
include('query.php');
?>
}
]
}
window.onload = function(){
var ctx = document.getElementById("pergunta1").getContext("2d");
window.myBar = new Chart(ctx).Bar(barChartData, {responsive : true
});
}
</script>
</body>
</html>
PHP
$total = mysql_query("SELECT * FROM carrefour WHERE statusPesquisa=2");
$linhaTotal = mysql_num_rows($total);
$inicio = 0;
echo "data : [";
while($inicio <= 5){
$query = "$query$inicio";
$row = "$row$inicio";
$notapergunta = "notapergunta$inicio";
$teste = mysql_query("SELECT COUNT(*) FROM carrefour WHERE notapergunta1=$inicio AND statusPesquisa=2")
$query = mysql_query("SELECT * FROM carrefour WHERE notapergunta1=$inicio AND statusPesquisa=2");
$row = mysql_num_rows($query);
if($inicio == 0) {
$percent = 0;
} else{
$percent = 359 / $row;
}
if($inicio != 5) {
echo round($percent).",";
}
else {
echo round($percent);
}
$inicio++;
}
echo "]";Discussão (1)
Carregando comentários...