Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
OLA PESSOAL!
Eu já gero graficos com PHPLOT, porem tá tendo um aqui que tá osso...
A ideia é pegar todos os TIPOS OCORRENCIAS distintos ex.: COBRANÇA, ENTREGA etc... e CONTAR quantas linhas existem com CADA TIPO DE OCORRENCIA ex.: COMBRANÇA 73, ENTREGA 21, etc...
Eu não estou conseguindo gerar um grafico com base nestes dados.
VEJA O CODIGO ABAIXO EU ACHO QUE O PROPREMA ESTÁ NA LINHA QUE TEM O eval (ante-penultima linha), lembrando que ele não retorna ERRO NENHUM, somente gera o grafico com 100%.
<?php
include('phplot/phplot.php'); //inclui a classe
//#####################################################
$nome_bd="banco_sac";
//## Conectando ao servidor MySql
$conexao = mysql_connect("localhost","root","*****");
//## Conectando ao Banco de dados
mysql_select_db($nome_bd, $conexao);
//#####################################################
//====================================================================================================================
//==== INICIO GERA GRAFICO === RECLAMAÇÃO: TIPOS DE OCORRENCIAS
//====================================================================================================================
$graph = new PHPlot(300,250);//tamanho 300x250 pixels
$graph->SetPlotType("pie"); //tipo do grafico
$graph->SetTextColor("#000000"); //cor da fonte
$graph->SetTitle("RECLAMAÇÕES \n tipos de ocorrencias");
$tabela = "reclamacao";
$sql = mysql_query("SELECT tipo as tp, COUNT(*) as qtd FROM $tabela GROUP BY tipo ORDER BY tipo ASC") or die ("Erro ao fazer SELECT: " . mysql_error());
$conta = mysql_num_rows($sql);
if($conta<1)
{
$conta=0;
}
$array_data= 'array('; $array_data .= 'array("'.$linha["tp"].'",';
$array_data .= '"'.$linha["qtd"].'",),';
}
while ($linha = mysql_fetch_array($sql));
}
$array_data .= ');';
eval("\$array_data2 = $array_data;");
$graph->SetDataValues($array_data2);// setar valores
$graph->DrawGraph();
//====================================================================================================================
//==== FIM GERA GRAFICO === RECLAMAÇÃO: TIPOS DE OCORRENCIAS
//====================================================================================================================
?>
OBRIGADO POR RESPONDER.
Tá dando um erro mas está correto!
Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\dario\fale_facil\graficos_reclamacao_por_tipos_ocorrencias.php on line 33
a linha 33 é essa
while($linha = mysql_fetch_array($sql){
<?php
include('phplot/phplot.php'); //inclui a classe
//#####################################################
$nome_bd="banco_sac";
//## Conectando ao servidor MySql
$conexao = mysql_connect("localhost","root","*****");
//## Conectando ao Banco de dados
mysql_select_db($nome_bd, $conexao);
//#####################################################
//====================================================================================================================
//==== INICIO GERA GRAFICO === RECLAMAÇÃO: TIPOS DE OCORRENCIAS
//====================================================================================================================
$graph = new PHPlot(300,250);//tamanho 300x250 pixels
$graph->SetPlotType("pie"); //tipo do grafico
$graph->SetTextColor("#000000"); //cor da fonte
$graph->SetTitle("RECLAMAÇÕES \n tipos de ocorrencias");
$tabela = "reclamacao";
$sql = mysql_query("SELECT tipo, COUNT(*) as qtd FROM $tabela GROUP BY tipo ORDER BY tipo ASC") or die ("Erro ao fazer SELECT: " . mysql_error());
while($linha = mysql_fetch_array($sql)){
$array_data[$linha['tipo']] = $linha['qtd'];
}
$graph->SetDataValues($array_data);// setar valores
$graph->DrawGraph();
//====================================================================================================================
//==== FIM GERA GRAFICO === RECLAMAÇÃO: TIPOS DE OCORRENCIAS
//====================================================================================================================
?>
Pra quem não entendeu o erro
tava faltand um parenteses fechando no while
no caso s estava fechando do mysql_fetch_array, e o while tava aberto
while($linha = mysql_fetch_array($sql)){
Foi isso que eu corrigi no meu post
Poxa.... era o parentese e nao a chave, putz!
mas que coisa... http://forum.imasters.com.br/public/style_emoticons/default/pinch.gif vejam o erro agora:
Warning: array_values() [function.array-values]: The argument should be an array in C:\xampp\htdocs\dario\fale_facil\phplot\phplot.php on line 2211
Warning: array_values() [function.array-values]: The argument should be an array in C:\xampp\htdocs\dario\fale_facil\phplot\phplot.php on line 2211
Warning: array_values() [function.array-values]: The argument should be an array in C:\xampp\htdocs\dario\fale_facil\phplot\phplot.php on line 2211
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\dario\fale_facil\phplot\phplot.php:2211) in C:\xampp\htdocs\dario\fale_facil\phplot\phplot.php on line 1466
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\dario\fale_facil\phplot\phplot.php:2211) in C:\xampp\htdocs\dario\fale_facil\phplot\phplot.php on line 1467
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\dario\fale_facil\phplot\phplot.php:2211) in C:\xampp\htdocs\dario\fale_facil\phplot\phplot.php on line 1468
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\dario\fale_facil\phplot\phplot.php:2211) in C:\xampp\htdocs\dario\fale_facil\phplot\phplot.php on line 1469
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\dario\fale_facil\phplot\phplot.php:2211) in C:\xampp\htdocs\dario\fale_facil\phplot\phplot.php on line 1475
‰PNG IHDR,ú,³ŠÁ9PLTEÂÂÂ’’’ÿÿÿ¾¾¾‡ÎëWž»ÿÏÿ¥ÏuÿÏÿÏî‚î¾R¾ðÿÿÀÏϺ¬„IDATxœí׋N£@@QÃüÿ?ëZ)B׳’¨›{Mú(…“aR_¦út/ß}¿©° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° k°Æ[g‡×/ö‡ûûQžœÜÓÒEXÓñ9=_ž÷{|âÿÃzû{ñçq¹m]/[³±»öñþñýWÇœwºm^¶nfñjätÖ{—be®l°Öã+°S¬™u·çÎwÜçåÃ[¾}½õË];³noÆó¥Î35~p‡ ÔýgXÓfÊm§Ð<±ÆÇºß’ûù5MÓ—±ÆëŒrsøŽ5N°Æý6œÖ·Ü¬Óúýî6ÜÌÒåÝ}‡cÊéÊ;ñÊŸ÷ÛmZDöãËʶŸÛ5k›íaÿøšiC9m–ü¶À>=ïÃ;ô»úMX×ýøÇúw zîlKm"#IEND®B‚
Fatal error: DrawGraph(): Empty data set in C:\xampp\htdocs\dario\fale_facil\phplot\phplot.php on line 1568
VEJAM COMO FICOU O CODIGO:
<?php
include('phplot/phplot.php'); //inclui a classe
//#####################################################
$nome_bd="banco_sac";
//## Conectando ao servidor MySql
$conexao = mysql_connect("localhost","root","****");
//## Conectando ao Banco de dados
mysql_select_db($nome_bd, $conexao);
//#####################################################
//==================================================================================================================
//==== INICIO GERA GRAFICO === RECLAMAÇÃO: TIPOS DE OCORRENCIAS
//==================================================================================================================
$graph = new PHPlot(300,250);//tamanho 300x250 pixels
$graph->SetPlotType("pie"); //tipo do grafico
$graph->SetShading(20); //Determina o 3D
$graph->SetTextColor("#000000"); //cor da fonte
$graph->SetTitle("RECLAMAÇÕES \n tipos de ocorrencias");
$tabela = "reclamacao";
$sql = mysql_query("SELECT tipo, COUNT(*) as qtd FROM $tabela GROUP BY tipo ORDER BY tipo ASC") or die ("Erro ao fazer SELECT: " . mysql_error());
while($linha = mysql_fetch_array($sql))
{
$array_data[$linha['tipo']] = $linha['qtd'];
}
$graph->SetDataValues($array_data);// setar valores
$graph->DrawGraph();?>
<?php
include('phplot/phplot.php'); //inclui a classe
//#####################################################
$nome_bd="banco_sac";
//## Conectando ao servidor MySql
$conexao = mysql_connect("localhost","root","****");
//## Conectando ao Banco de dados
mysql_select_db($nome_bd, $conexao);
//#####################################################
//==================================================================================================================
//==== INICIO GERA GRAFICO === RECLAMAÇÃO: TIPOS DE OCORRENCIAS
//==================================================================================================================
$graph = new PHPlot(300,250);//tamanho 300x250 pixels
$graph->SetPlotType("pie"); //tipo do grafico
$graph->SetShading(20); //Determina o 3D
$graph->SetTextColor("#000000"); //cor da fonte
$graph->SetTitle("RECLAMAÇÕES \n tipos de ocorrencias");
$tabela = "reclamacao";
$sql = mysql_query("SELECT tipo, COUNT(*) as qtd FROM $tabela GROUP BY tipo ORDER BY tipo ASC") or die ("Erro ao fazer SELECT: " . mysql_error());
while($linha = mysql_fetch_array($sql))
{
$array_data[$linha['tipo']] = $linha['qtd'];
}
$data = array($array_data);
$graph->SetDataValues($data);// setar valores
$graph->DrawGraph();
//==================================================================================================================
//==== FIM GERA GRAFICO === RECLAMAÇÃO: TIPOS DE OCORRENCIAS
//==================================================================================================================
Acrescentei a linha, igual o Dee postou:
$data = array($array_data);
O grafico está gerando! Mas está errado porque está gerando 50% para cada fatia da pizza (tem 2 fatias era pra ter 3 fatias)...Então mude de pie para bars, ou seja, de pizza para barras, mas ainda está mostrando somente 2 itens iguais.
Vejam o grafico aqui: http://www.4shared.com/file/141063477/aa7a40eb/grafico.html
Então eu dei um print_r na $data e apareceu:
Array ( [0] => Array ( [COBRANÇA] => 3 [ENTREGA] => 1 [PROPAGANDA] => 1 ) )
ou seja, realmente existem os 3 itens!Não entendo!
<?php
include('phplot/phplot.php'); //inclui a classe
//#####################################################
$nome_bd="banco_sac";
//## Conectando ao servidor MySql
$conexao = mysql_connect("localhost","root","*****");
//## Conectando ao Banco de dados
mysql_select_db($nome_bd, $conexao);
//#####################################################
//====================================================================================================================
//==== INICIO GERA GRAFICO === RECLAMAÇÃO: TIPOS DE OCORRENCIAS
//====================================================================================================================
$graph = new PHPlot(300,250);//tamanho 300x250 pixels
$graph->SetPlotType("pie"); //tipo do grafico
$graph->SetTextColor("#000000"); //cor da fonte
while($linha = mysql_fetch_array($sql){
$graph->SetDataValues($array_data);// setar valores
$graph->DrawGraph();
//====================================================================================================================
//==== FIM GERA GRAFICO === RECLAMAÇÃO: TIPOS DE OCORRENCIAS
//====================================================================================================================
?>