321
إنشاء رسوميات ديناميكية باستخدام PHP
البرنامج النصي gd_graph.php (تابع)
31.
32.
33.
34.
35.
/* Create Base Image */
$image ImageCreate($width, $height);
/* Allocate Colors */
$white ImageColorAllocate($image, 235, 235, 235); $blue ImageColorAllocate ($image, 0, 0, 255);
36.
$red ImageColorAllocate ($image, 255, 0, 0);
37.
/* Find Largest Item In Values Array */
38.
39.
40.
41.
42.
43.
}
44.
45.
46.
47.
48.
49.
$x = $xoffset + 5;
50.
51.
$y$height $yoffset
-
52.
53.
54.
55.
56.
$greatest = 0;
for($i = 0; $i < sizeof($values); $i++) {
$values[$i] = trim($values[$i]);
if ($values[$i] > $greatest) $greatest = $values[$i];
/* Determine Scale And Spacing */
$scale = ($height / $greatest) .8;
-
$h_spacing= floor(($width $xoffset) / sizeof($values)) / 2; $barwidth = $h_spacing;
/* Draw Bars, Labels, and Values*/
for($i= 0; $i < sizeof($values); $i++) {
($values[$i]
*
$scale);
ImageFilledRectangle($image, $x, $y $x + $barwidth, $height
$yoffset, $red);
ImageString ($image, $sm_font, $x, $y-12,
$values[$i], $blue);
$labels [$i] = trim($labels[$i]);
ImageString ($image, $md_font, $x, $height - $yoffset
+ 2, $labels [$i], $blue);
$x+={$h_spacing * 2);
-
57.
}
58.
/* Determine Ticks */
59.
60.
$ticks_every = "1";
for ($i= 1; $i < (round (log10($greatest))); $i++) {
61.
$ticks_every .= "0";
62.
}
€3. /* Draw Ticks And Numbers */
64.
for($i = 0; $i < $height $yoffset; $i+= $ticks_every* $scale) {
ص٣٢١