I can't plot a treemap using PHP

30 views
Skip to first unread message

Isadora Almeida

unread,
Jun 1, 2018, 4:41:34 PM6/1/18
to Google Visualization API
I'm trying to plot a treemap into my we system, I'm using php and mysql.
I have already several graphics (columns, pie, line, etc), but this one I just can't plot.

Here's part of the code where I search the data
$table = array();

			//colunas 
			$table['cols'] = array(

				array('label'=>'Rota','type'=>'string'),

				array('label'=>'Rota2','type'=>'string'),

                 array('label'=>'Entregas','type'=>'number'),

					array('label'=>'Entregas_cor','type'=>'number')
				);

			//rows
				$rows = array();
				
					$query = $pdo->prepare("SELECT COUNT(sk_carga) as qtd_entregas, carga_rota as rota FROM dim_lg_carga where id_empresa = :sk_empresa GROUP BY 2");

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


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


								$rota =$linha['rota'];
								
								$rota2 =null;
								
							$qtd_entregas = intval($linha['qtd_entregas']);
								
								
						$qtd_entregas_cor = intval($linha['qtd_entregas']);

								$temp = array();

								$temp[] = array('v'=>$rota);

								$temp[] = array('v'=>$rota2);

								
								$temp[] = array('v'=>$qtd_entregas);

								$temp[] = array('v'=>$qtd_entregas_cor);


								$rows[] = array('c'=>$temp);
					}

						
						$table['rows'] = $rows;


							$jsonTable = json_encode($table);
							
							
							echo $jsonTable;




Here's the json code:

	google.setOnLoadCallback(desenharGraficoEntregasRotas);
			

						function desenharGraficoEntregasRotas(){
							// ajax
							
							var jsonDados10 = $.ajax({
							//url:"Model/Empresa/get_entregas_motorista.php",
							url:'http://localhost/sistema-bi-web/Model/Empresa/get_rotas_entregas.php',
								dataType: "json",
								async: false

							}).responseText;


						var options10 = {
									     minColor: '#f00',
								          midColor: '#ddd',
								          maxColor: '#0d0',
								          headerHeight: 15,
								          fontColor: 'black',
								          showScale: true

						};
					
							//dados do grafico
							var dados10 = new google.visualization.DataTable(jsonDados10);

						
						var grafico10= new google.visualization.TreeMap(document.getElementById('grafico_entregas_rota'));

							// desenha o grafico de acordo com os parametros passados
							grafico10.draw(dados10, options10); 

		}

Eriovaldo Andrietta

unread,
Jun 1, 2018, 9:18:57 PM6/1/18
to Google Visualization API

Hi Isadora, 

I am facing the same problem.
I can see the result generated via php. I can see the echo result in the chrome, but when try to send data to google api via json structure it is not working.
Your code is similar to mine.
Let me know if you got some news about this issue.
Regards
Eriovaldo
Reply all
Reply to author
Forward
0 new messages