PIECHART

14 views
Skip to first unread message

Hugo Leonardo

unread,
May 23, 2017, 10:56:58 AM5/23/17
to Google Visualization API
Bom would have a new program, Google Earth. Estou precando de uma ajuda, pois, tenho uma taba no banco de dados com os campos (pergunta, ótimo, bomb, ample), evil o campo pergunta recebe uma string e os outros campos numero. You're welcome, you're welcome, you're welcome, you're welcome, and you're welcome to talk to me, you're welcome, and you're welcome.

Below is code that calls json


<script type="text/javascript">
google.charts.load('visualization', '1', {packages:['corechart'],'language':'pt-BR'});
google.charts.setOnLoadCallback(desenhaGraficoPerguntas);

function desenhaGraficoPerguntas(){

    var jsonData = $.ajax({
    url:"getAllDespesas.php",
       dataType: "json",
       async:false
          }).responseText;

        var dados = new google.visualization.DataTable(jsonData);      


        var option = {
           width:960,
           height:500,
           title: 'Gráficos de Perguntas'           
        }

        var chart = new google.visualization.PieChart(document.getElementById('div-chart'));
   chart.draw(dados, option);
</script>
<h3>Gráfico Pizza</h3>
<div id="div-chart" class="div-chart"></div>
<hr>

</body>
</html>


The other file that generates json follows below



  try{

         require_once 'conexao.php';
          //$conn  = new PDO("mysql:host=".HOST.";dbname=".DATABASE,USER,PASS);
          $table = array(); 
          $table['cols']=array(
                                 array('label'=>'Pergunta', 'type'=>'string'), 
                                 array('label'=>'otimo', 'type'=>'number'),
                                 array('label'=>'bom', 'type'=>'number'),
                                 array('label'=>'ruim', 'type'=>'number')
                           );

            $rows = array();
            

          $result = $pdo ->query('SELECT * FROM frases_novas ');
          if($result){
         
          while ($linha = $result->fetch(PDO::FETCH_ASSOC)) {
         

             $pergunta = $linha['texto'];
                  $resposta_zero=$linha['otimo'];
           $resposta_um=$linha['bom'];
           $resposta_dois=$linha['ruim'];
           $temp=array(); 
                  $temp[]=array('v'=>utf8_encode($pergunta));
           $temp[]=array('v'=>$resposta_zero);
                  $temp[]=array('v'=>$resposta_um);
           $temp[]=array('v'=>$resposta_dois);
           $rows[]=array('c'=>$temp);
}

$table['rows']=$rows;

$jsonTable =json_encode($table);
              }

              echo $jsonTable;

          }catch(PDOException $i){
          print "Erro:".$i->getMessage();
          }

         
       
     }
}




And the graph generated is this





But my goal is to have this graph

In the database, this graph must be mounted per line.


Reply all
Reply to author
Forward
0 new messages