Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [GD2] Generowanie wykresu słupkowego, na local działa a na serwerze nie
djgarsi
post
Post #1





Grupa: Zarejestrowani
Postów: 459
Pomógł: 26
Dołączył: 1.06.2009

Ostrzeżenie: (0%)
-----


Witam. Próbuję zrobić na podstawie artykułu php.pl wykres słupkowy. Niestety nie obyło się bez błędów.
Na serwerze localhost wykres wyświetla się ładnie, jednak na serwerze "w necie" nie działa.

Oto mój kod:
  1. <?php
  2. ini_set('display_errors', 'On');
  3. error_reporting( E_ALL );
  4. function gen_wykres($dane, $width = 500, $height = 250, $dist = 10, $tlo = 'grad.jpg', $font = 'Dosis-ExtraBold.ttf')
  5. {
  6. $wykres = imagecreatetruecolor($width, $height);
  7. $bcg_image = imagecreatefromjpeg($tlo);
  8. $background = imagecolorat($bcg_image, 0, imagesy($bcg_image) - 1);
  9.  
  10. imagefill($wykres, 0, 0, $background);
  11. imagecopyresampled($wykres, $bcg_image, 0, 0, 0, 0, $width, imagesy($bcg_image), imagesx($bcg_image), imagesy($bcg_image));
  12.  
  13. $count_all = array_sum($dane);
  14. $max = max($dane);
  15. $el_width = round(($width - $dist) / count($dane));
  16. $mnoznik = ($height - ($dist * 2)) / $max;
  17.  
  18. foreach ($dane as $key => $value)
  19. {
  20. $col = round(255 - (150 / count($dane)) * $i);
  21. $colors[$key] = imagecolorallocate($wykres, $col, 200, 0);
  22. $text_color[$key] = imagecolorallocate($wykres, 0, 0, 0);
  23.  
  24. $top = $height - ($dist) - $value * $mnoznik;
  25. $left = $i * $el_width + $dist;
  26.  
  27. imagefilledrectangle($wykres, $left, $top, $left + $el_width - $dist, $height - $dist, $colors[$key]);
  28. imagettftext($wykres, 10, 90, $left + $el_width / 2, $height - $dist - 2, $text_color[$key], $font, $key.' - '.$value.'');
  29.  
  30. $i++;
  31. }
  32.  
  33. return $wykres;
  34. }
  35. header('Content-Type: image/png');
  36. include('../include/db_connect.php');
  37. $dane = array();
  38. $Query="SELECT * FROM odslony ORDER by id DESC LIMIT 10";
  39. $result = mysql_query($Query) or die (mysql_error());
  40. while ( $row = mysql_fetch_array($result))
  41. {
  42. $data = $row['odslony'];
  43. $dane[$row['id']] = $row['odslony'];
  44. }
  45. $wykres = gen_wykres($dane, 600, 180, 10);
  46. imagepng($wykres);
  47. ?>


jak widać jest niemal identyczny jak w artykule.
Czy mógłby mi ktoś wskazać jakieś błędy?


--------------------
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 21.08.2025 - 03:03