How to generate a histogram dynamically using the GD Library of PHP

time:10-07-05 forum:PHP tools and code
  The reprints of http://hi.baidu.com/iamljj/blog/item/42dcbf2f878834301e308948.html

PHP are excellent in the performance of image operations. We can easily achieve the map and table sketch with the help of a free GD library. The following will introduce the pie chart, the line diagram and the histogram of the author, and the method of their use. The characteristics of these sections are that they do not need to be copied into your code. Only the calculated data are used as parameters to get the corresponding graphical effect

histogram
Set
should first determine the scale of the longitudinal axis, determine the maximum axis of the scale of the scale
and then determine the width of the image according to the number of data obtained, then the image can be created
calculate the height of each color column, the height of the column can be calculated with the height of the column
the coordinate axis is drawn in a straight line, Mark the scale value
with rectangle filling color column, and label data value

[code].lt;
$kuan=30;
$kuan=30; / / / / / color column width
$jiange=20; / / / / color column spacer
$zuo=20; / / / / left blank holder; / / right left empty
$xia=10; / / / / / /
$zuidashujuzhi=1; / /
if ($_GET.#91;.Quot; a.quot;.#93; ==.quot;.Quot;) ) {
if (! Is_numeric ($shuju.#91; $i.#93;)) die (.Quot; error id:1.quot;);
if. A br / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / />$zhugaodu = array () = imagecreate = array ();
$image = imagecreate ($img_kuan, $img_gao);
$white = imagecolorallocate. E ($image, 0x00, 0x99, 0x00),
imagecolorallocate ($image, 0xCC, 0x33, 0x00). 0x99, 0x33),
imagecolorallocate ($image, 0xCC, 0xCC, 0x99),
imagecolorallocate ($image, 0x99, > >); The horizontal axis
imageline ($image, $zuo, $img_gao-$xia, $img_kuan-$you/2, $img_gao-$xia, $zuobiao_yanse);
/ / / / / / / / / / / / / longitudinal axis calibration. $image, $zuo, $shang, $zuo 6, $shang, $zuobiao_yanse);
imagestring ($image, 3, $zuo/4, $shang, round). 3, $zuo/4, $shang ($img_gao-$shang-$xia) *1/4, round ($zuidashujuzhi*3/4), $zuobiao_yanse);
imageline ($image, $zuo, $shang). Dashujuzhi*2/4, $zuobiao_yanse);
imageline ($image, $zuo, $img_gao-$shang-$xia) *3/4, $zuo 6, $shang ($img_gao-$shang-$xia). The height of the column is
for ($i=0; $i.lt; count ($shuju); $i) {
array_push ($zhugaodu, round). Nge $i* ($kuan $jiange), $shang ($img_gao-$shang-$xia) -$zhugaodu.#91; $i.#93; $zuo $jiange $i* ($kuan); $shuju_yanse_int=0 (
}else{
$shuju_yanse_int;
}
}
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / $shuju.#91; $i.#93; $zuobiao_yanse);
}
header ('Content-type: image/png');
imagepng ($image); 3,4.quot; /.gt; [/code]
in which the value of a is calculated by yourself, the text format of
a is a string of several data connected by "," connected to the get mode.

also uses a HTML solution to solve the problem of the name of the cross axis scale:
dynamically generates a table to place a horizontal axis coordinate scale name based on the number of data, such as

[code].lt; table width=.quot; 550.quot; border=.quot; 0.quot; 0.quot; societies; societies; Dding=.quot; 0.quot;.Gt;
.lt; tr align=.quot; center.quot;.Gt;
.lt;
  • 2
  • 3

prev:PHP implements code conversion between G... next:MSN, QQ online instant chat web embedded...
post comment
Notice



approved   Utility tools or components, framewo...   Mother recorded the 44 weeping of he...   The 71 moments of survival of the po...   Post retirement pension crisis: perh...   How much do you know about the histo...
rand   Talk about 10 MySQL mistakes that PH...   10 MySQL errors that PHP developers ...   Eliminate 3 Chinese characters from ...   Importing large databases to virtual...   Using regular expressions to verify ...
ads

other

Because all the contents of this site are reproduced from other media, the intention is to provide free services to the public, but it does not mean that this site agrees with its views, and can not be responsible for the authenticity of its verification, such as the copyright unit or individual of the manuscript does not want to publish on this site, please Contact me, I will immediately remove it, thank you. Contact: atseashawk@163.com