Display php chart in columns

0

I've created a php test that is working properly. But I have a small problem, because the test is composed of 128 questions which are divided into 7 groups. But the number of questions in each group is different.

The complete code:

$sql = 'SELECT * FROM questoes WHERE ativo = 1';
mysqli_query($conn, 'SET NAMES utf8');
$retorno = mysqli_query($conn, $sql);
$totaisChakras = array(1 => 24, 2 => 34, 3 => 24, 4 => 27, 5 => 20, 6 => 16, 7 => 16);
$arrPorcentagens = array(1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0);
// 24   34  24  27  20  16  16
$arrayQuestoesChakras = array(1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0);
while($lista = mysqli_fetch_assoc($retorno)){

    foreach($resultados as $idx => $value){
        if($value > 0){
            if($lista['nrPergunta'] == $idx){
                if($lista['ch1']){
                    $arrayQuestoesChakras[1]++;
                }
                if($lista['ch2']){
                    $arrayQuestoesChakras[2]++;
                }
                if($lista['ch3']){
                    $arrayQuestoesChakras[3]++;
                }
                if($lista['ch4']){
                    $arrayQuestoesChakras[4]++;
                }
                if($lista['ch5']){
                    $arrayQuestoesChakras[5]++;
                }
                if($lista['ch6']){
                    $arrayQuestoesChakras[6]++;
                }
                if($lista['ch7']){
                    $arrayQuestoesChakras[7]++;
                }
            }
        }
    }
}

for($x = 1; $x <= 7; $x++){
    if($arrayQuestoesChakras[$x] > 0){
        $arrPorcentagens[$x] = round(($arrayQuestoesChakras[$x] * 100) / $totaisChakras[$x]);
    }else{
        $arrPorcentagens[$x] = 2;
    }
}

In summary, the part that displays the result is this:

<div class="progress-bar progress-bar-raiz active" role="progressbar" aria-valuenow="<?php echo $arrayQuestoesChakras[1] ?>" aria-valuemin="0" aria-valuemax="24" style="height: <?php echo $arrPorcentagens[1] ?>%;">

  

See the height of the column I'm determining by:

style="height: <?php echo $arrPorcentagens[1] ?>%;">

Although it works very well, the problem is that proportionally the look can be glaring. Since each group has a specific amount of questions.

What better way to solve this? is it common to use css to determine the height of a graph generated by php ??

    
asked by anonymous 02.10.2018 / 22:57

0 answers