效果:
<?php
/***
* @project Bar Graph Program
* @license GPL
* @package
* @file GrapBar.php
* @date 2007-4-3
* @version 1.0
* @last modified
* 定义 柱状图(柱形图) 类
*
* 注意,使用前请确保字体路径存在并允许访问,如果出错,还要检查在php.ini配置中的open_basedir项,如果没此路径请添加,或在程序中设置包含
*
* 智能化的柱状图程序,用于报表等
*
***/
define("DEFAULT_FONT_PATH", "c:/windows/fonts/simhei.ttf");
class SingleBar
{
private $_x;
private $_y;
private $_h;
public $_l = 50;
private $_w = null;
private $_srcPoints = array();
private $_points = array();
public function __construct($x, $y, $h, $l = 50, $w = null)
{
$this->_x = $x;
$this->_y = $y;
$this->_h = $h;
$this->_l = $l;
$this->_w = $w;
$this->_srcPoints = $this->getSrcPoints();
$this->_points = $this->getPoints();
}
public function getSrcPoints()
{
return array(
array($this->_x , $this->_y),
array($this->_x+$this->_l , $this->_y),
array($this->_x+(1.35*$this->_l), $this->_y-(0.35*$this->_l)),
array($this->_x+(0.35*$this->_l), $this->_y-(0.35*$this->_l)),
array($this->_x , $this->_y+$this->_h),
array($this->_x+$this->_l , $this->_y+$this->_h),
array($this->_x+(1.35*$this->_l), $this->_y+$this->_h-(0.35*$this->_l))
);
}
public function getPoints()
{
$points = array();
foreach($this->_srcPoints as $key => $val)
{
$points[] = $val[0];
$points[] = $val[1];
}
return $points;
}
public function getTopPoints()
{
return array_slice($this->_points, 0, 8); //顶坐标
}
public function getBelowPoints()
{
return array_merge(array_slice($this->_points, 0, 2), array_slice($this->_points, 8, 4), array_slice($this->_points, 2, 2)); //下坐标
}
public function getRightSidePoints()
{
return array_merge(array_slice($this->_points, 2, 2), array_slice($this->_points, 10, 4), array_slice($this->_points, 4, 2)); //右侧坐标
}
public function draw($image, $topColor, $belowColor, $sideColor, $borderColor = null, $typ