PHP function _php tutorial for column chart

Source: Internet
Author: User
PHP Functions for column graphs

Keywords: PHP

#为了方便起见, I made a function to make a column chart.
/* Parameter Description:
$graphdata: Percent data (Y-axis)
$label: X-axis Title
$data: Actual data (Y-axis)
$graphwidth: Image width
$graphheight: Image Height
$graphscale: Height factor (for $graphheight/100)
$graphfont: Font number
$BG; background color value
$text: Text color values
$grid: Edge Color values
$bar: The color value of the bar
$BZ: Remarks (Chinese is not supported)
*/
function Timage (
$graphdata, $label, $data,
$graphwidth, $graphheight, $graphscale, $graphfont,
$BG, $text, $grid, $bar, $BZ)
{

Header ("Content-type:image/gif");
$image =imagecreate ($graphwidth +50, $graphheight +50);
$bgcolor = Imagecolorallocate ($image, $BG [0], $BG [1], $BG [2]);
$textcolor = Imagecolorallocate ($image, $text [0], $text [1], $text [2]);
$gridcolor =imagecolorallocate ($image, $grid [0], $grid [1], $grid [2]);
$barcolor =imagecolorallocate ($image, $bar [0], $bar [1], $bar [2]);
$gridabelwidth =imagefontwidth ($graphfont) *3+1;
$gridableheight = Imagefontheight ($graphfont);

Imageline ($image, $gridlabelwidth, 0, $gridlabelwidth, $graphheight-1, $gridcolor);
Imageline ($image, 0, $graphheight-1, $graphwidth-1, $graphheight-1, $gridcolor);
for ($i =0; $i < $graphheight; $i + = $graphheight/10)
{
Imagedashedline ($image, 0, $i, $graphwidth-1, $i, $gridcolor);
Imagestring ($image, $graphfont, 0, $i, round (($graphheight-$i)/$graphscale), $textcolor);
}

$barwidth = (($graphwidth-$gridlabelwidth)/count ($graphdata)) -30;#¿øöæöùµäxü¿í¶è
for ($i =0; $i {
$BARTOPX = $gridlabelwidth + (($i + 1) *20) + ($i * $barwidth); #¿øöæöù¿¿xóµä¾ààë
$BARBOTTOMX = $bartopx + $barwidth;
$barbottomy = $graphheight -1;#¿øöæöùµäïâ±ß½ç
$bartopy = $barbottomy-($graphdata [$i]* $graphscale);
Imagefilledrectangle ($image, $bartopx, $bartopy, $barbottomx, $barbottomy, $barcolor);
$labelx 1= $bartopx;
$labely 1= $bartopy-15;
$labelx 2= $bartopx;
$labely 2= $graphheight;
Imagestring ($image, $graphfont, $labelx 1, $labely 1, "$graphdata [$i]". " % ", $textcolor);
Imagestring ($image, $graphfont, $labelx 2, $labely 2, "$label [$i]", $textcolor);
Imagestringup ($image, $graphfont, $labelx 1+10, $labely 1-$gridableheight, "$data [$i]", $textcolor);
}
Imagestring ($image, $graphfont, 1, $graphheight +30, $BZ, $textcolor);
Imagegif ($image);

}
?>

http://www.bkjia.com/PHPjc/532264.html www.bkjia.com true http://www.bkjia.com/PHPjc/532264.html techarticle PHP to do column chart function keywords: php #为了方便起见, I made a function to make a column chart//Parameter description: $graphdata: Percent data (Y-axis) $label: X-axis title $data ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.