设为首页
加为收藏
联系我们
  • 电子商务
  • 软件网络
  • 看天下
  • 营销财经
  • 关闭导航
  • 网络编程
  • 数据库类
  • 关闭导航
  • 网络编程
  • 社交礼仪
  • 数据库类
  • 人文地理
  • 关闭导航
  • 编程工具
  • 电子书籍
  • 关闭导航
  • 生活休闲
  • 演讲讲座
  • 视频教程
  • 经典影视
  • 关闭导航
  • 您的位置: 首页 > 文章中心 > 网络编程 > PHP

    JpGraph --功能超级强大的PHP画图库

    时间: 2008-09-25  信息来源: 博客园  作者: 编辑整理  点击数:

    内容提示:非常好用,非常强大的画图库.

    从数据库中读取数据到jpgraph图表中        
      1、将./src/Examples目录中的文件example16.2.php以及./src目录中的文件jpgraph_bar.php、jpgraph_gradient.php、jpgraph_line.php、jpgraph_plotmark.inc、jpgraph.php拷贝到同一目录下。
    2、建立数据库jpg,数据库表test
    建立2个字段:
    id(主键):int
    number:int
    并添加一些数据
    3、修改example16.2.php
    修改后的代码

     <?php
    include  ("jpgraph.php");
    include  ("jpgraph_line.php");
    include  ("jpgraph_bar.php");

    $connect=mysql_connect("localhost","root","");
    mysql_select_db("jpg",$connect);
    $query=mysql_query("select  *  from  test",$connect);
    $i=0;
    while  ($array=mysql_fetch_array($query))  {
    $l2datay[$i]=$array["number"];
    $i++;
    }
    mysql_close($connect);


    //  Create  the  graph.  
    $graph  =  new  Graph(400,200,"auto");  
    $graph->SetScale("textlin");

    $graph->img->SetMargin(40,130,20,40);
    $graph->SetShadow();


    //  Create  the  bar  plot
    $bplot  =  new  BarPlot($l2datay);
    $bplot->SetFillColor("orange");
    $bplot->SetLegend("Result");

    //  Add  the  plots  to  t'he  graph

    $graph->Add($bplot);


    $graph->title->Set("Adding  a  line  plot  to  a  bar  graph  v1");
    $graph->xaxis->title->Set("X-title");
    $graph->yaxis->title->Set("Y-title");

    $graph->title->SetFont(FF_FONT1,FS_BOLD);
    $graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
    $graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);

    //$graph->xaxis->SetTickLabels($datax);
    //$graph->xaxis->SetTextTickInterval(2);

    //  Display  the  graph
    $graph->Stroke();
    ?>

    4、刷新页面即可看到结果
     
    Tags: JpGraph,画图库 责任编辑:aboutstudy
     
      关于我们 友情链接 网站地图 广告服务 联系我们 管理登陆  
      鄂ICP备07014143号  
      Powered by EmpireCMS 5.0  
      Template designed by 直来直往.
      联系信息: QQ 365931563 Email:jiangtian001@sina.com  
      ©CopyRight 2007-2008, SKDE.CN, Inc. All Rights Reserved