Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

fsf

[RESOLVIDO] Grafico

Recommended Posts

Pessoal, Bom dia....Estou com algumas duvidas para gerar um gráfico em php usando a biblioteca gd2!!!!Consegui num livro o codigo abaixo..Mas estou com alguns problemas para gerar grafico...O codigo:

include "Connections/conexao.php";// get current results of poll, regardless of whether they voted $query = 'select tipo.descricao, sum(solicita.codexame) as totalfrom tb_exame exame,	 tb_tipo_exame tipo,	 tb_solicitaexame solicitawhere exame.codexame = solicita.codexame and	  solicita.codtipoexame = tipo.codtipoexamegroup by tipo.descricaoorder by tipo.descricao asc';$result = mysql_query($query); $num_exame = mysql_num_rows($result); // calculate total number of votes so far$total_exames=0;while ($row = mysql_fetch_object ($result)) {	$total_exames +=  $row->total;}mysql_data_seek($result, 0);  // reset result pointer/*******************************************  Initial calculations for graph *******************************************/// set up constantsputenv('GDFONTPATH=C:\WINDOWS\Fonts');$width=500;		// width of image in pixels - this will fit in 640x480$left_margin = 50; // space to leave on left of graph$right_margin= 50; // ditto right   $bar_height = 40;  $bar_spacing = $bar_height/2; $font = 'arial';$title_size= 16; // point$main_size= 12; // point$small_size= 12; // point$text_indent = 10; // position for text labels from edge of image// set up initial point to draw from$x = $left_margin + 60;  // place to draw baseline of the graph$y = 50;		  // ditto $bar_unit = ($width-($x+$right_margin)) / 100;   // one "point" on the graph// calculate height of graph - bars plus gaps plus some margin$height = $num_exames * ($bar_height + $bar_spacing) + 50;   /*******************************************  Set up base image *******************************************/// create a blank canvas$im = ImageCreateTrueColor($width,$height);   	 // Allocate colors   $white=ImageColorAllocate($im,255,255,255);   $blue=ImageColorAllocate($im,0,64,128);   $black=ImageColorAllocate($im,0,0,0);   $pink = ImageColorAllocate($im,255,78,243); $text_color = $black;$percent_color = $black;$bg_color = $white;$line_color = $black;$bar_color = $blue;$number_color = $pink;// Create "canvas" to draw on ImageFilledRectangle($im,0,0,$width,$height,$bg_color);   // Draw outline around canvas ImageRectangle($im,0,0,$width-1,$height-1,$line_color);   // Add title$title = 'Poll Results';$title_dimensions = ImageTTFBBox($title_size, 0, $font, $title);//linhas 82$title_length = $title_dimensions[2] - $title_dimensions[0];$title_height = abs($title_dimensions[7] - $title_dimensions[1]);$title_above_line = abs($title_dimensions[7]);$title_x = ($width-$title_length)/2;  // center it in x $title_y = ($y - $title_height)/2 + $title_above_line; // center in y gapImageTTFText($im, $title_size, 0, $title_x, $title_y, 			 $text_color, $font, $title);  // Draw a base line from a little above first bar location // to a little below last  ImageLine($im, $x, $y-5, $x, $height-15, $line_color);   /*******************************************  Draw data into graph *******************************************/// Get each line of db data and draw corresponding bars   while ($row = mysql_fetch_object ($result)) {  if ($total_exames > 0)	$percent = intval(round(($row->total/$total_exames)*100));  else 	$percent = 0;  // display percent for this value    $percent_dimensions = ImageTTFBBox($main_size, 0, $font, $percent.'%');  $percent_length = $percent_dimensions[2] - $percent_dimensions[0];  ImageTTFText($im, $main_size, 0, $width-$percent_length-$text_indent, 			   $y+($bar_height/2), $percent_color, $font, $percent.'%');      if ($total_exames > 0)	$right_value = intval(round(($row->total/$total_exames)*100));  else	$right_value = 0;  // length of bar for this value     $bar_length = $x + ($right_value * $bar_unit);     // draw bar for this value     ImageFilledRectangle($im, $x, $y-2, $bar_length, $y+$bar_height, $bar_color);     // draw title for this value     ImageTTFText($im, $main_size, 0, $text_indent, $y+($bar_height/2), 			   $text_color, $font, "$row->descricao");    // draw outline showing 100%   ImageRectangle($im, $bar_length+1, $y-2, 				($x+(100*$bar_unit)), $y+$bar_height, $line_color);     // display numbers     ImageTTFText($im, $small_size, 0, $x+(100*$bar_unit)-50, $y+($bar_height/2),			   $number_color, $font, $row->total.'/'.$total_exames);  // move down to next bar  $y=$y+($bar_height+$bar_spacing);   }   /*******************************************  Display image *******************************************/Header('Content-type:  image/png');ImagePNG($im);   /*******************************************  Clean up *******************************************/ImageDestroy($im);
O erro:

Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename in C:\Arquivos de programas\Apache Software Foundation\Apache2.2\htdocs\teste\show_poll.php on line 82Warning: imagettftext() [function.imagettftext]: Invalid font filename in C:\Arquivos de programas\Apache Software Foundation\Apache2.2\htdocs\teste\show_poll.php on line 89Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename in C:\Arquivos de programas\Apache Software Foundation\Apache2.2\htdocs\teste\show_poll.php on line 107Warning: imagettftext() [function.imagettftext]: Invalid font filename in C:\Arquivos de programas\Apache Software Foundation\Apache2.2\htdocs\teste\show_poll.php on line 110Warning: imagettftext() [function.imagettftext]: Invalid font filename in C:\Arquivos de programas\Apache Software Foundation\Apache2.2\htdocs\teste\show_poll.php on line 125Warning: imagettftext() [function.imagettftext]: Invalid font filename in C:\Arquivos de programas\Apache Software Foundation\Apache2.2\htdocs\teste\show_poll.php on line 133Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename in C:\Arquivos de programas\Apache Software Foundation\Apache2.2\htdocs\teste\show_poll.php on line 107Warning: imagettftext() [function.imagettftext]: Invalid font filename in C:\Arquivos de programas\Apache Software Foundation\Apache2.2\htdocs\teste\show_poll.php on line 110Warning: imagettftext() [function.imagettftext]: Invalid font filename in C:\Arquivos de programas\Apache Software Foundation\Apache2.2\htdocs\teste\show_poll.php on line 125Warning: imagettftext() [function.imagettftext]: Invalid font filename in C:\Arquivos de programas\Apache Software Foundation\Apache2.2\htdocs\teste\show_poll.php on line 133

Compartilhar este post


Link para o post
Compartilhar em outros sites

Obrigado beraldo....So mais uma duvida..O path da fonte tambem poderia ser uma pasta dentro de localhost???

Compartilhar este post


Link para o post
Compartilhar em outros sites

Beraldo..So to com mais um duvida...Para visualizar a imagem tenho que expandi-la!!Existe alguma forma de daixar a umagem com o seu tamanho original????

Compartilhar este post


Link para o post
Compartilhar em outros sites

A imagem fica com um tamanho reduzido!!!Ai clico no botão expandir do windows para ela voltar ao tamanho normal.

Compartilhar este post


Link para o post
Compartilhar em outros sites

fsf, pelo que entendi deve ser o padrão do navegador. Quando uma imagem é maior do que a resolução de tela, ele reduz e deixa uma opção para ver no tamanho original. É isso que ocorre?Se sim, você não deve contar que seja exibida já ampliada para os usuários, pois trata-se de configuração no browser ;)[]sAnderson Mello

Compartilhar este post


Link para o post
Compartilhar em outros sites

E isso que esta ocorrendo...Obrigado pela dica!!

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.