haidong 发表于 2010-2-24 13:43:27

html 柱状图的类 - 水平

<FONT face=新宋体><FONT color=#0000bb>&lt;?php<BR></FONT><FONT color=#007700>class </FONT></FONT><FONT face=新宋体 color=#0000bb>histogram_h<BR></FONT><FONT face=新宋体 color=#007700>{<BR></FONT><FONT face=新宋体><FONT color=#ff8000>/***********************************<BR>   * H: horizontal(水平)<BR>   * HTML 柱状图<BR>   * 设计: 第二信息(www.DearInfo.com) / 唐辉<BR>   * 源稿设计日期: 2004年11月11日<BR>   * PHP社区: http://php.DearInfo.com<BR>   * 转载时请保留作者信息及出处, 多谢!<BR>   * 使用方法:<BR>   * $htg      = new histogram_h;<BR>   * $htg-&gt;num= "250,370,621,720,326,455,132,345,611,126,551,266";<BR>   * $htg-&gt;label= "1月,2月,3月,4月,5月,6月,7月,8月,9月,10月,11月,12月";<BR>   * $htg-&gt;show();<BR>   ************************************/<BR><BR>//数值<BR></FONT><FONT color=#007700>var </FONT><FONT color=#0000bb>$num</FONT></FONT><FONT face=新宋体 color=#007700>;<BR><BR></FONT><FONT face=新宋体><FONT color=#ff8000>//低部标签值<BR></FONT><FONT color=#007700>var </FONT><FONT color=#0000bb>$label</FONT></FONT><FONT face=新宋体 color=#007700>;<BR><BR></FONT><FONT face=新宋体><FONT color=#ff8000>//柱状图宽度, 默认为399, 用户可自定义<BR></FONT><FONT color=#007700>var </FONT><FONT color=#0000bb>$width</FONT><FONT color=#007700>=</FONT><FONT color=#0000bb>399</FONT></FONT><FONT face=新宋体 color=#007700>;<BR><BR></FONT><FONT face=新宋体><FONT color=#ff8000>//每条柱的高度,默认为25, 用户可自定义<BR></FONT><FONT color=#007700>var </FONT><FONT color=#0000bb>$perheight</FONT><FONT color=#007700>=</FONT><FONT color=#0000bb>25</FONT></FONT><FONT face=新宋体 color=#007700>;<BR><BR></FONT><FONT face=新宋体><FONT color=#ff8000>//柱与柱之间的间隔<BR></FONT><FONT color=#007700>var </FONT><FONT color=#0000bb>$cellspacing</FONT><FONT color=#007700>=</FONT><FONT color=#0000bb>5</FONT></FONT><FONT face=新宋体><FONT color=#007700>;<BR><BR>function </FONT><FONT color=#0000bb>show</FONT></FONT><FONT face=新宋体 color=#007700>()<BR>{<BR>    </FONT><FONT face=新宋体><FONT color=#ff8000>//获取外部数值<BR>    </FONT><FONT color=#0000bb>$shu</FONT><FONT color=#007700>=</FONT><FONT color=#0000bb>split</FONT><FONT color=#007700>(</FONT><FONT color=#dd0000>","</FONT><FONT color=#007700>,</FONT><FONT color=#0000bb>$this</FONT><FONT color=#007700>-&gt;</FONT><FONT color=#0000bb>num</FONT></FONT><FONT face=新宋体 color=#007700>);<BR>    </FONT><FONT face=新宋体><FONT color=#ff8000>//获取标签值<BR>    </FONT><FONT color=#0000bb>$biaoqian</FONT><FONT color=#007700>=</FONT><FONT color=#0000bb>split</FONT><FONT color=#007700>(</FONT><FONT color=#dd0000>","</FONT><FONT color=#007700>,</FONT><FONT color=#0000bb>$this</FONT><FONT color=#007700>-&gt;</FONT><FONT color=#0000bb>label</FONT></FONT><FONT face=新宋体 color=#007700>);<BR>    </FONT><FONT face=新宋体><FONT color=#ff8000>//颜色, 默认为20种, 如果客户数据超过20种, 则回到第一种, 如此循环.<BR>    </FONT><FONT color=#0000bb>$color</FONT><FONT color=#007700>= array(</FONT><FONT color=#dd0000>'#97bd00'</FONT><FONT color=#007700>,</FONT><FONT color=#dd0000>'#009900'</FONT><FONT color=#007700>,</FONT><FONT color=#dd0000>'#cc3300'</FONT></FONT><FONT face=新宋体><FONT color=#007700>,<BR>            </FONT><FONT color=#dd0000>'#ffcc00'</FONT><FONT color=#007700>,</FONT><FONT color=#dd0000>'#3366cc'</FONT><FONT color=#007700>,</FONT><FONT color=#dd0000>'#33cc33'</FONT></FONT><FONT face=新宋体><FONT color=#007700>,<BR>            </FONT><FONT color=#dd0000>'#ff9933'</FONT><FONT color=#007700>,</FONT><FONT color=#dd0000>'#cccc99'</FONT><FONT color=#007700>,</FONT><FONT color=#dd0000>'#99cc66'</FONT></FONT><FONT face=新宋体><FONT color=#007700>,<BR>            </FONT><FONT color=#dd0000>'#66ff99'</FONT><FONT color=#007700>,</FONT><FONT color=#dd0000>'#4f6600'</FONT><FONT color=#007700>,</FONT><FONT color=#dd0000>'#003300'</FONT></FONT><FONT face=新宋体><FONT color=#007700>,<BR>            </FONT><FONT color=#dd0000>'#481000'</FONT><FONT color=#007700>,</FONT><FONT color=#dd0000>'#7d6400'</FONT><FONT color=#007700>,</FONT><FONT color=#dd0000>'#173064'</FONT></FONT><FONT face=新宋体><FONT color=#007700>,<BR>            </FONT><FONT color=#dd0000>'#1a6a1a'</FONT><FONT color=#007700>,</FONT><FONT color=#dd0000>'#974b00'</FONT><FONT color=#007700>,</FONT><FONT color=#dd0000>'#78793c'</FONT></FONT><FONT face=新宋体><FONT color=#007700>,<BR>            </FONT><FONT color=#dd0000>'#557e27'</FONT><FONT color=#007700>,</FONT><FONT color=#dd0000>'#009337'</FONT></FONT><FONT face=新宋体><FONT color=#007700>);      <BR>    if (</FONT><FONT color=#0000bb>$shu</FONT><FONT color=#007700>==</FONT><FONT color=#dd0000>""</FONT><FONT color=#007700>) die(</FONT><FONT color=#dd0000>"error id:1"</FONT></FONT><FONT face=新宋体><FONT color=#007700>);<BR>    </FONT><FONT color=#0000bb>$shuju</FONT><FONT color=#007700>=</FONT><FONT color=#0000bb>split</FONT><FONT color=#007700>(</FONT><FONT color=#dd0000>","</FONT><FONT color=#007700>,</FONT><FONT color=#0000bb>$shu</FONT></FONT><FONT face=新宋体 color=#007700>);<BR>    </FONT><FONT face=新宋体><FONT color=#ff8000>//计算最大值<BR>    </FONT><FONT color=#007700>for(</FONT><FONT color=#0000bb>$i</FONT><FONT color=#007700>=</FONT><FONT color=#0000bb>0</FONT><FONT color=#007700>;</FONT><FONT color=#0000bb>$i</FONT><FONT color=#007700>&lt;</FONT><FONT color=#0000bb>count</FONT><FONT color=#007700>(</FONT><FONT color=#0000bb>$shu</FONT><FONT color=#007700>);</FONT><FONT color=#0000bb>$i</FONT></FONT><FONT face=新宋体><FONT color=#007700>++)<BR>    {<BR>      if(!</FONT><FONT color=#0000bb>is_numeric</FONT><FONT color=#007700>(</FONT><FONT color=#0000bb>$shu</FONT><FONT color=#007700>[</FONT><FONT color=#0000bb>$i</FONT><FONT color=#007700>])) die(</FONT><FONT color=#dd0000>"error id:2"</FONT></FONT><FONT face=新宋体><FONT color=#007700>);<BR>      if(</FONT><FONT color=#0000bb>$shu</FONT><FONT color=#007700>[</FONT><FONT color=#0000bb>$i</FONT><FONT color=#007700>]&gt;</FONT><FONT color=#0000bb>$zuidashu</FONT><FONT color=#007700>) </FONT><FONT color=#0000bb>$zuidashu</FONT><FONT color=#007700>=</FONT><FONT color=#0000bb>$shu</FONT><FONT color=#007700>[</FONT><FONT color=#0000bb>$i</FONT></FONT><FONT face=新宋体><FONT color=#007700>];<BR>    }<BR></FONT><FONT color=#0000bb>?&gt;</FONT></FONT><CODE><FONT color=#000000><BR><BR><BR>&lt;table border="0" cellpadding="0" cellspacing="</FONT></CODE><CODE><FONT color=#000000><FONT color=#0000bb>&lt;?php </FONT><FONT color=#007700>echo </FONT><FONT color=#0000bb>$this</FONT><FONT color=#007700>-&gt;</FONT><FONT color=#0000bb>cellspacing</FONT><FONT color=#007700>; </FONT><FONT color=#0000bb>?&gt;</FONT></FONT></CODE><CODE><FONT color=#000000>"&gt;<BR>    </FONT></CODE><CODE><FONT color=#000000><FONT color=#0000bb>&lt;?php<BR>      </FONT><FONT color=#007700>for(</FONT><FONT color=#0000bb>$i</FONT><FONT color=#007700>=</FONT><FONT color=#0000bb>0</FONT><FONT color=#007700>,</FONT><FONT color=#0000bb>$j</FONT><FONT color=#007700>=</FONT><FONT color=#0000bb>0</FONT><FONT color=#007700>;</FONT><FONT color=#0000bb>$i</FONT><FONT color=#007700>&lt;</FONT><FONT color=#0000bb>count</FONT><FONT color=#007700>(</FONT><FONT color=#0000bb>$shu</FONT><FONT color=#007700>);</FONT><FONT color=#0000bb>$i</FONT><FONT color=#007700>++,</FONT><FONT color=#0000bb>$j</FONT><FONT color=#007700>++)<BR>      {<BR>      if(</FONT><FONT color=#0000bb>$j</FONT><FONT color=#007700>&gt;</FONT><FONT color=#0000bb>19</FONT><FONT color=#007700>){</FONT><FONT color=#0000bb>$j</FONT><FONT color=#007700>=</FONT><FONT color=#0000bb>0</FONT><FONT color=#007700>;}<BR>    </FONT><FONT color=#0000bb>?&gt;</FONT></FONT></CODE><CODE><FONT color=#000000><BR><BR>&lt;tr&gt;<BR>    &lt;td&gt;&lt;p align="right"&gt;</FONT></CODE><CODE><FONT color=#000000><FONT color=#0000bb>&lt;?php </FONT><FONT color=#007700>echo</FONT><FONT color=#ff8000>/*打印左边标签*/ </FONT><FONT color=#0000bb>$biaoqian</FONT><FONT color=#007700>[</FONT><FONT color=#0000bb>$i</FONT><FONT color=#007700>]; </FONT><FONT color=#0000bb>?&gt;</FONT></FONT></CODE><CODE><FONT color=#000000>&lt;/td&gt;<BR>    &lt;td&gt;<BR>   &lt;table border="0" cellpadding="0" cellspacing="0" height="</FONT></CODE><CODE><FONT color=#000000><FONT color=#0000bb>&lt;?php </FONT><FONT color=#007700>echo </FONT><FONT color=#0000bb>$this</FONT><FONT color=#007700>-&gt;</FONT><FONT color=#0000bb>perheight</FONT><FONT color=#007700>; </FONT><FONT color=#0000bb>?&gt;</FONT></FONT></CODE><CODE><FONT color=#000000>"&gt;<BR>   &lt;tr&gt;<BR>       &lt;td width="</FONT></CODE>&lt;? <PRE>echo floor(($this-&gt;width/$zuidashu)*$shu[$i]);?&gt;" bgcolor="</PRE><CODE><FONT color=#000000><FONT face=新宋体><FONT color=#0000bb>&lt;?php </FONT><FONT color=#ff8000>/*柱状颜色*/ </FONT><FONT color=#007700>echo </FONT><FONT color=#0000bb>$color</FONT><FONT color=#007700>[</FONT><FONT color=#0000bb>$j</FONT><FONT color=#007700>]; </FONT><FONT color=#0000bb>?&gt;</FONT></FONT></FONT></CODE><FONT face=新宋体><CODE><FONT color=#000000>"&gt;&amp;nbsp;&lt;/td&gt;<BR>       &lt;td&gt;&amp;nbsp;</FONT></CODE><CODE><FONT color=#000000><FONT color=#0000bb>&lt;?php </FONT><FONT color=#ff8000>/*在柱状图的顶端输出数值*/ </FONT><FONT color=#007700>echo </FONT><FONT color=#0000bb>$shu</FONT><FONT color=#007700>[</FONT><FONT color=#0000bb>$i</FONT><FONT color=#007700>]; </FONT><FONT color=#0000bb>?&gt;</FONT></FONT></CODE></FONT><CODE><FONT face=新宋体 color=#000000>&lt;/td&gt;<BR>   &lt;/tr&gt;<BR>   &lt;/table&gt;<BR>   &lt;/td&gt;<BR>&lt;/tr&gt;<BR></FONT></CODE><CODE><FONT face=新宋体><SPAN#0000bb">&lt;?php<BR><SPAN#ffffff 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN#0000bb">      }<BR><SPAN#ffffff 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN#0000bb">?&gt;<BR></FONT></CODE><PRE>&lt;/table&gt;</PRE><CODE><FONT face=新宋体><SPAN#ffffff 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN#0000bb">&lt;?php<BR><SPAN#ffffff 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN#0000bb">} //End function<BR><SPAN#ffffff 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN#007700">} // End histogram Class<BR><SPAN#ffffff 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN#0000bb">?&gt;</SPAN></FONT><BR></CODE><PRE> </PRE>
页: [1]
查看完整版本: html 柱状图的类 - 水平