Home > Backend Development > PHP Tutorial > PHP bar chart implementation code_PHP tutorial

PHP bar chart implementation code_PHP tutorial

WBOY
Release: 2016-07-21 15:42:21
Original
896 people have browsed it

If you still have questions, you can add me on QQ: 460634320 and let’s discuss together.
Rendering:

Copy code The code is as follows:

function createImage($data,$twidth,$tspace,$height){
header("Content-Type:image/jpeg");
$dataname = array();
$datavalue = array ();//The value in data
$i = 0;
$j = 0;
$k = 0;
$num = sizeof($data);

foreach($data as $key => $val){
$dataname[] = $key;
$datavalue[] = $val;
}

$width = $num * ($twidth + $tspace) + 20 ;//Get the width of the image
$im = imagecreate($width,$height);//Create the image

$bgcolor = imagecolorallocate($ im,255,255,255);//Background color
$jcolor = imagecolorallocate($im,255,255,0);//Background color of the rectangle
$acolor = imagecolorallocate($im,0,0,0);/ /Color of line

imageline($im,25,$height-20,$width-5,$height -20,$acolor);//X-axis
imageline($im,25, $height-20,25,2,$acolor);//Y-axis
while($i< $num){
imagefilledrectangle($im,$i*($tspace+$twidth)+40,$ height-$datavalue[$i]-20,$i*($twidth+$tspace)+$tspace+40,$height-20,$jcolor);//Draw a rectangle
imagestring($im,3,$ i*($tspace+$twidth)+40+$twidth/2,$height-$datavalue[$i]-35,$datavalue[$i],$acolor);//Write the value on the column
imagestring($im,3,$i*($tspace+$twidth)+40+$twidth/2,$height-15,$dataname[$i],$acolor);//Write the value below the column
$i ++;

}
while($j < 400/10){
imageline($im,25,($height-20)-$j*8,28 ,($height-20)-$j*8,$acolor);//Draw the scale
imagestring($im,2,5,($height-30)-$j*8,$j*10 ,$acolor);//Mark the scale value
$j = $j +10;
}
imagejpeg($im);
}
$data =array("1" =>25,"2"=>30,"3" =>21 );
createImage($data,40,40,300);

?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320966.htmlTechArticleIf you still have questions, you can add me at QQ: 460634320, let’s discuss together. Rendering: Copy the code. The code is as follows: ?php function createImage($data,$twidth,$tspace,$height){ header("Con...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template