资讯   |   开发   |   选机中心   |   产品大全 | IBM | 惠普 | 联想 | 戴尔 | 苹果 | 神舟
更多: | 华硕 | 明基 | 方正 | 紫光 | TCL | 夏新 | 联宝 | 宏碁 | 七喜 | 长城 | 清华同方 | 海尔 | 三星 | 东芝 | 索尼 | 富士通 | LG | 技术 | ddnoon
当前位置:笔记本 > 编程开发 >
Advertisement
文章正文

给你一个画饼图的,画直方图直接用img控制其宽高就可实现吧_编程

类型:转载   责任编辑:asp.net   日期:2007/05/23


热门软件下载:


   
  • 一个好用的UBB类! 
  • 回复:关于PHP聊天室的讨论 
  • 一个简单的图形计数器,需要MYSQL,GD的支持,LINUX下PHP4RC1通过 
  • 土特产:PHP4.0RC2-Win32安装指南(中文版) 
  • PHP3,PHP4,ASP运行速度测试 
  • 如何PHP的图形函数中显示汉字。 
  • 一段代码示例代码,目前可以兼容odbc和OCI两种连接数据库方法! 
  • apache_1.3.12,php4.0bx,informix安装心得 
  • Focus on Mock Object(2) 
  • 林锐——软件工程思想 
  • 页面导航:

    正文内容:
    //调用方法:<image src="chart.php">
    //chart.php为本文文件名

    <?

    /*
    把角度转换为弧度
    */
    function radians ($degrees)
    {
    return($degrees * (pi()/180.0));
    }
    /*
    ** 取得在圆心为(0,0)圆上 x,y点的值
    */
    function circle_point($degrees, $diameter)
    {
    $x = cos(radians($degrees)) * ($diameter/2);
    $y = sin(radians($degrees)) * ($diameter/2);

    return (array($x, $y));
    }
    // 填充图表的参数
    $chartdiameter = 200; //图表直径
    $chartfont = 2; //图表字体
    $chartfontheight = imagefontheight($chartfont);//图表字体的大小

     require(mysql.php3);
     $sql=new mysql_class;
     $sql->create(star);
     $sql->query("select * from serch where answer=富士通常昊 九段");
     $record1=$sql->rows;
     $sql->query("select * from serch where answer=富士通曹薰铉 九段");
     $record2=$sql->rows; 

    $chartdata = array( $record1,$record2);//用于生成图表的数据,可通过数据库来取得来确定
    //$chartlabel = array("常昊九段", "曹薰铉九段"); //数据对应的名称

    //确定图形的大小
    $chartwidth = $chartdiameter + 20;
    $chartheight = $chartdiameter + 20 +
    (($chartfontheight + 2) * count($chartdata));

    //确定统计的总数
    for($index = 0; $index < count($chartdata); $index++)
    {
    $charttotal += $chartdata[$index];
    }

    $chartcenterx = $chartdiameter/2 + 10;
    $chartcentery = $chartdiameter/2 + 10;


    //生成空白图形
    $image = imagecreate($chartwidth, $chartheight);

    //分配颜色
    $colorbody = imagecolorallocate($image, 0xe4, 0xe6, 0xd1);
    $colorborder = imagecolorallocate($image, 0x00, 0x00, 0x00);
    $colortext = imagecolorallocate($image, 0x00, 0x00, 0x00);

    $colorslice[] = imagecolorallocate($image, 0xff, 0x00, 0x00);
    $colorslice[] = imagecolorallocate($image, 0x00, 0x00, 0xff);


    //填充背境
    imagefill($image, 0, 0, $colorbody);


    /*
    ** 画每一个扇形
    */
    $degrees = 0;
    for($index = 0; $index < count($chartdata); $index++)
    {
    $startdegrees = round($degrees);
    $degrees += (($chartdata[$index]/$charttotal)*360);
    $enddegrees = round($degrees);

    $currentcolor = $colorslice[$index%(count($colorslice))];

    //画图f
    imagearc($image,$chartcenterx,$chartcentery,$chartdiameter,
    $chartdiameter,$startdegrees,$enddegrees, $currentcolor);

    //画直线
    list($arcx, $arcy) = circle_point($startdegrees, $chartdiameter);
    imageline($image,$chartcenterx,$chartcentery,floor($chartcenterx + $arcx),
    floor($chartcentery + $arcy),$currentcolor);
    //画直线
    list($arcx, $arcy) = circle_point($enddegrees, $chartdiameter);
    imageline($image,$chartcenterx,$chartcentery,ceil($chartcenterx + $arcx),
    ceil($chartcentery + $arcy),$currentcolor);

    //填充扇形
    $midpoint = round((($enddegrees - $startdegrees)/2) + $startdegrees);
    list($arcx, $arcy) = circle_point($midpoint, $chartdiameter/2);
    imagefilltoborder($image,floor($chartcenterx + $arcx),floor($chartcentery + $arcy),
    $currentcolor,$currentcolor);
    }

    //画边框
    imagearc($image,
    $chartcenterx,
    $chartcentery,
    $chartdiameter,
    $chartdiameter,
    0,
    180,
    $colorborder);

    imagearc($image,
    $chartcenterx,
    $chartcentery,
    $chartdiameter,
    $chartdiameter,
    180,
    360,
    $colorborder);


    imagearc($image,
    $chartcenterx,
    $chartcentery,
    $chartdiameter+7,
    $chartdiameter+7,
    0,
    180,
    $colorborder);

    imagearc($image,
    $chartcenterx,
    $chartcentery,
    $chartdiameter+7,
    $chartdiameter+7,
    180,
    360,
    $colorborder);


    imagefilltoborder($image,
    floor($chartcenterx + ($chartdiameter/2) + 2),
    $chartcentery,
    $colorborder,
    $colorborder);


    //画图例
    for($index = 0; $index < count($chartdata); $index++)
    {
    $currentcolor = $colorslice[$index%(count($colorslice))];
    $liney = $chartdiameter + 20 + ($index*($chartfontheight+2));

    //draw color box
    imagerectangle($image,
    10,
    $liney,
    10 + $chartfontheight,
    $liney+$chartfontheight,
    $colorborder);

    imagefilltoborder($image,
    12,
    $liney + 2,
    $colorborder,
    $currentcolor);

    //画标签
    imagestring($image,
    $chartfont,
    20 + $chartfontheight,
    $liney,
    "$chartdata[$index]",
    $colortext);
    }

    //到此脚本 已经生了一幅图像的,现在需要的是把它发到浏览器上,重要的一点是要将标头发给浏览器,让它知道是一个gif文件。不然的话你只能看到一堆奇怪的乱码

    header("content-type: image/gif");
    //输出生成的图片
    imagegif($image);
    ?>

     

     
    热门推荐笔记本: 新蓝笔记本
    相关文章:
    webmaster:popbb@126.com   最佳浏览:1024X768 MSIE
    ©2007 popbb.net All Rights Reserved