The examples in this article describe the graph of curve statistics that PHP implements. Share to everyone for your reference, specific as follows:
<?php/****************************** * Line chart Generation function * Youd * 090207-01 ******************************/func tion Line_stats_pic ($value _y, $width, $high, $strong =1, $fix =0) {//y value processing functions function line_point_y ($num, $width, $high, $max _num_add, $min _num_add, $y _pxdensity) {$return = $high-floor (($num-$min _num_add+ $y _pxdensity)/($max _num_add-$min _
Num_add)/$high));
return $return;
///Parameter processing $allnum =sizeof ($value _y); $max _num=max ($value _y); The maximum value $min _num=min ($value _y); The minimum value $limit _m= $max _num-$min _num; Extremely poor $max _num_add= $max _num+ $limit _m*0.1; The axle maximum value $min _num_add= $min _num-$limit _m*0.1; Axis minimum $limit = $max _num_add-$min _num_add; Extreme difference-Axis y $y _pxdensity= ($max _num_add-$min _num_add)/$high; Y-Axis density $x _pxdensity=floor ($width/$allnum); X-axis density reset ($value _y);
Returning the array pointer to zero $i = 0;
foreach ($value _y as $val) {$point _y[$i]=line_point_y ($val, $width, $high, $max _num_add, $min _num_add, $y _pxdensity);
$i + +; } $zero _y=line_point_y(0, $width, $high, $max _num_add, $min _num_add, $y _pxdensity); The Y-value of 0 points $empty _size_x= (strlen ($max _num) > strlen ($min _num) strlen ($max _num): strlen ($min _num)) *5+3;
Left blank//Picture stream start Header ("Content-type:image/png");
$pic =imagecreate ($width + $empty _size_x+10, $high +13); Imagecolorallocate ($pic, 255,255,255); Background color $color _1=imagecolorallocate ($pic, 30,144,255); Line Color $color _2=imagecolorallocate ($pic, 0,0,0); Black $color _3=imagecolorallocate ($pic, 194,194,194);//Gray//Imagesetthickness ($pic, 1); Grid line width $y _line_width=floor ($width/100); Number of vertical grid lines $y _line_density= $y _line_width==0? 0:floor ($width/$y _line_width); Longitudinal grid line density $point _zero_y= $zero _y > $high?
$high: $zero _y; Imagestring ($pic, 1, $empty _size_x-1, $high +4, "0", $color _2); 0-Point Axis mark for ($i =1; $i <= $y _line_width $i + +) {//Draw vertical grid line imagesetthickness ($pic, 1);
Grid line width imageline ($pic, $y _line_density* $i + $empty _size_x,0, $y _line_density* $i + $empty _size_x, $high, $color _3); Imagesetthickness ($pic, 2); Axis Point line width imageline ($pic, $y _line_density* $i + $empty _size_x, $point _zero_y-4, $y _line_density* $i + $empty _size_x, $point _
Zero_y, $color _2); Imagestring ($pic, 1,100* $i + $empty _size_x-5, $high +4, $allnum/$y _line_width* $i, $color _2); Axis Mark} $x _line_width=floor ($high/30); Number of horizontal grid lines $x _line_density= $x _line_width==0? 0:floor ($high/$y _line_width); Horizontal Grid line Density if ($zero _y > $high) {//Draw horizontal grid line imagestring ($pic, 1,0, $high -3,round ($min _num_add, $fix), $color _2); /0 Dot Axis mark for ($i =1; $i <= $x _line_width $i + +) {imagesetthickness ($pic, 1); Grid line width imageline ($pic, 0+ $empty _size_x, $high-$x _line_density* $i, $width + $empty _size_x, $high-$x _line_density* $i, $
Color_3); Imagesetthickness ($pic, 2); Axis Point line width imageline ($pic, 0+ $empty _size_x, $high-$x _line_density* $i, 3+ $empty _size_x, $high-$x _line_density* $i, $color _
2); Imagestring ($pic, 1,0, $high-$x _line_density* $i -3,round ($limit/$x _line_width* $i + $min _num_add, $fix), $color _2); Axis Mark}}else{imagestring ($pic, 1, $empty _size_x-8, $zEro_y, "0", $color _2); 0-Point Axis mark for ($i =1; $i <= ceil ($x _line_width/2); $i + +) {imagesetthickness ($pic, 1); Grid line width imageline ($pic, 0+ $empty _size_x, $zero _y-$x _line_density* $i, $width + $empty _size_x, $zero _y-$x _line_density*$
I, $color _3); if ($zero _y+ $x _line_density* $i < $high) {Imageline ($pic, 0+ $empty _size_x, $zero _y+ $x _line_density* $i, $width +$
empty_size_x, $zero _y+ $x _line_density* $i, $color _3); } imagesetthickness ($pic, 2); Axis Point line width imageline ($pic, 0+ $empty _size_x, $zero _y-$x _line_density* $i, 3+ $empty _size_x, $zero _y-$x _line_density* $i, $
color_2); if ($zero _y+ $x _line_density* $i < $high) {Imageline ($pic, 0+ $empty _size_x, $zero _y+ $x _line_density* $i, 3+ $empty _
size_x, $zero _y+ $x _line_density* $i, $color _2); Imagestring ($pic, 1,0, $zero _y-$x _line_density* $i -3,round ($limit/$x _line_width* $i, $fix), $color _2); Axis Mark if ($zero _y+ $x _line_density* $i < $high) {imagestring ($pic, 1,0, $zero _y+ $x _line_density* $i -3,round (-$limit/ $x _line_width* $i, $fix), $color _2); //axis Mark}}//Draw Axis imagesetthickness ($pic, 2);
Axis width imageline ($pic, 1+ $empty _size_x,0,1+ $empty _size_x, $high, $color _2); if ($zero _y > $high) {//x axis position imageline ($pic, 0+ $empty _size_x, $high, $width + $empty _size_x, $high, $color _2);
else{imageline ($pic, 0+ $empty _size_x, $zero _y, $width + $empty _size_x, $zero _y, $color _2);}//produce polyline $point _x=0;
$j = 0; Imagesetthickness ($pic, $strong); Line thickness while ($j +1 < $allnum) {Imageline ($pic, $point _x+2+ $empty _size_x, $point _y[$j], $point _x+ $x _pxdensity+2+$
empty_size_x, $point _y[$j +1], $color _1);
$point _x+= $x _pxdensity;
$j + +;
} imagepng ($pic);
Imagedestroy ($pic);
}/* Function description and Example parameter description: $value _y--------contains the array you want to generate a line chart, requiring the key value to increment from 0. $width--------The grid width (not white edge) of the generated line chart $high--------height $strong-------line thickness (default is 1) $fix the number of digits reserved for the-------data (default is rounding)/for ($i =0; $i
<100; $i + +) {$value = rand (1,200);
$value _y[]= $value;
Line_stats_pic ($value _y,500,100,1,1);?>
More about PHP Interested readers can view the site topics: "PHP graphics and pictures Operating skills summary", "PHP file Operation Summary", "PHP Array" operation Skills Encyclopedia, "PHP Basic Grammar Introductory Course", "PHP Operations and Operator Usage Summary", " Introduction to PHP object-oriented programming program, "PHP Network Programming Skills Summary", "PHP string (String) Usage Summary", "Php+mysql database Operation Tutorial" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design.