php绘制柱状图

本文介绍如何利用PHP来绘制柱状图,展示具体实现过程和最终效果。
摘要由CSDN通过智能技术生成

效果:


<?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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值