Google chart, PHP and Ajax - Pizza chart does not show

0

I'm not able to plot the pie chart on the google chart. When I change the graph type to Barchart or columnchart, it plots, but when I put piechart it does not divide it.

File that takes DB data

<?php

require('../../Controller/conexao_bd/conexao_dw_bi.php');
class ContasPagas{

    public function pesquisaContasPagasForne($sk_empresa_atual){

    try{

            $sk_empresa = $sk_empresa_atual; 
            $pdo = Conexao::getInstance();
            $table = array();

            //colunas 
                $table['cols'] = array(
                    array('label'=>'Fornecedor','type'=>'string'),
                    array('label'=>'QTD','type'=>'number')
                );


            //rows
            $rows = array();                    

            $query = $pdo->prepare("SELECT COUNT(fato.valor_lancamento) as qtd_contas, forne.cnpj_cpf_fornecedor as doc_forne, forne.nome_fornecedor as forne FROM fato_lancamento_contabil as fato INNER JOIN dim_fornecedor as forne ON forne.cnpj_cpf_fornecedor = fato.cnpj_cpf_forne_cliente WHERE dim_empresa_sk_empresa = :sk_empresa AND dim_cliente_sk_cliente IS NULL AND dim_fornecedor_sk_fornecedor IS NOT NULL GROUP BY 2,3");

            $query->bindParam(':sk_empresa',$sk_empresa, PDO::PARAM_INT);
            $query->execute();


                    while ($linha=$query->fetch(PDO::FETCH_ASSOC)){                 

                        $forne = $linha['forne'];
                        $qtd_contas = $linha['qtd_contas'];
                        $temp = array();
                        $temp[] = array('v'=>$forne);
                        $temp[] = array('v'=>$qtd_contas);
                        $rows[] = array('c'=>$temp);
                }

                $table['rows'] = $rows;
                $jsonTable = json_encode($table);                   

                echo $jsonTable;


        }catch(PDOException $error){

            print "Erro: ".$error->getMessage();
        }
    }
}
?>

JS script

<script type="text/javascript">

    google.load('visualization','1',{'packages' : ['corechart', 'table'],'language':'pt-BR'}); // pacotes de gráficos e tabela
    google.setOnLoadCallback(desenharGraficoPagamentosForne_pie);   

    function desenharGraficoPagamentosForne_pie(){

        // ajax
        var jsonDados5 = $.ajax({
            url:"http://localhost/sistema-bi-web/Model/Empresa/get_qt_contas_pagas_fornce.php",
            dataType: "json",
            async: false
        }).responseText;

        var options5 = {
            title: 'x'
        };

        //dados do grafico
        var dados5 = new google.visualization.DataTable(jsonDados5);

        var grafico5 = new google.visualization.PieChart(document.getElementById('grafico_pagamentos_forne_pie'));

        // desenha o grafico de acordo com os parametros passados
        grafico5.draw(dados5, options5); 
    }

</script>
    
asked by anonymous 20.04.2018 / 16:59

1 answer

0

I managed to resolve. I had to do the int parse in the qtd_contas variable, which was coming as String by json.

$ qtd_contas = intval ($ line ['qtd_contacts']);

    
20.04.2018 / 19:32