/**
- * PHP GD library generates line chart, histogram, pie chart
- * by bbs.it-home.org
- */
- $img _gao=170;
- $img _kuan=0;
- $jiange the interval between the =30;//and the point, the resulting image width automatically changes depending on how much data is passed in.
- Left blank $zuo =20;//
- $you =20;//Right Blank
- Leave blank on $shang =20;//
- Leave blank $xia =20;//
- $zuidashujuzhi = 1;
- $p _x = Array ();//Dot Horizontal
- $p _y = Array ();//Point ordinate
- $y _name=split (",", $_get["X_name"]);
- if ($_get["a"]== "") Die ("Error id:0");
- $shuju =split (",", $_get["a"]);
- To get the longitudinal axis maximum value
- for ($i =0; $i<>
- if (!is_numeric ($shuju [$i])) die ("Error id:1");
- if ($shuju [$i]> $zuidashujuzhi) $zuidashujuzhi = $shuju [$i];
- }
- Get the image width
- $img _kuan= $zuo + $you +count ($shuju) * $jiange;
- Then create an image resource
- $image = Imagecreate ($img _kuan, $img _gao);
- Grey background
- $white = Imagecolorallocate ($image, 0xEE, 0xEE, 0xEE);
- The axes are shown in black
- $zuobiao _yanse = imagecolorallocate ($image, 0x00, 0x00, 0x00);
- Polyline is shown in blue
- $xian _yanse = imagecolorallocate ($image, 0x00, 0x00, 0xFF);
- Draw coordinates
- Horizontal
- Imageline ($image, $zuo, $img _gao-$xia, $img _kuan-$you/2, $img _gao-$xia, $zuobiao _yanse);
- longitudinal axis
- Imageline ($image, $zuo, $shang/2, $zuo, $img _gao-$xia, $zuobiao _yanse);
- Get the coordinates of each point
- for ($i =0; $i<>
- Array_push ($p _x, $zuo + $i * $jiange);
- Array_push ($p _y, $shang +round (($img _gao-$shang-$xia) * (1-$shuju [$i]/$zuidashujuzhi));
- }
- Longitudinal axis Scale
- Imageline ($image, $zuo, $shang, $zuo +6, $shang, $zuobiao _yanse);
- Imagestring ($image, 1, $zuo/4, $shang, $zuidashujuzhi, $zuobiao _yanse);
- Imageline ($image, $zuo, $shang + ($img _gao-$shang-$xia) *1/4, $zuo +6, $shang + ($img _gao-$shang-$xia) *1/4, $zuobiao _ Yanse);
- Imagestring ($image, 1, $zuo/4, $shang + ($img _gao-$shang-$xia) *1/4, $zuidashujuzhi *3/4, $zuobiao _yanse);
- Imageline ($image, $zuo, $shang + ($img _gao-$shang-$xia) *2/4, $zuo +6, $shang + ($img _gao-$shang-$xia) *2/4, $zuobiao _ Yanse);
- Imagestring ($image, 1, $zuo/4, $shang + ($img _gao-$shang-$xia) *2/4, $zuidashujuzhi *2/4, $zuobiao _yanse);
- Imageline ($image, $zuo, $shang + ($img _gao-$shang-$xia) *3/4, $zuo +6, $shang + ($img _gao-$shang-$xia) *3/4, $zuobiao _ Yanse);
- Imagestring ($image, 1, $zuo/4, $shang + ($img _gao-$shang-$xia) *3/4, $zuidashujuzhi *1/4, $zuobiao _yanse);
- Horizontal scale
- for ($i =0; $i<>
- Imageline ($image, $zuo + $i * $jiange, $img _gao-$xia, $zuo + $i * $jiange, $img _gao-$xia-6, $zuobiao _yanse);
- Imagestring ($image, 1, $zuo + $i * $jiange-$jiange/4, $shang + ($img _gao-$shang-$xia) +2, $y _name[$i], $zuobiao _yanse);
- }
Line
- $shuju _yanse_int=0;
- for ($i =0; $i<>
- if ($i +1<>count ($shuju)) {
- Imageline ($image, $p _x[$i], $p _y[$i], $p _x[$i +1], $p _y[$i +1], $xian _yanse);
- Imagefilledrectangle ($image, $p _x[$i]-1, $p _y[$i]-1, $p _x[$i]+1, $p _y[$i]+1, $xian _yanse);
- }
- }
- The last loop does not draw the final point effect, and there are additional
- Imagefilledrectangle ($image, $p _x[count ($shuju) -1]-1, $p _y[count ($shuju) -1]-1, $p _x[count ($shuju) -1]+1, $p _y[count ($shuju) -1]+1, $xian _yanse);
Callout Data value
- for ($i =0; $i<>
- Imagestring ($image, 3, $p _x[$i]+4, $p _y[$i]-12, $shuju [$i], $zuobiao _yanse);
- }
- Set File header
- Header (' content-type:image/png ');
- Output image
- Imagepng ($image);
- Freeing resources
- Imagedestroy ($image);
- ?>
Copy CodeSecond, use the method to insert the following code where the image needs to be displayed:
Copy CodeDescription: Where A's value is calculated by itself; a text format is a string of several data concatenated by the ",", get method passed in. Since writing to the graphics in Chinese requires more PHP environment configuration, here is an HTML solution: You only need to dynamically generate a table to place the horizontal coordinate scale name according to the number of data. Example:
- for ($i =0; $i <12; $i + +) {
- }
- echo "
- ?>
Copy Code |