不显示图表

时间:2015-02-27 16:01:13

标签: php mysql graph plot

我遵循了本教程http://www.ebrueggeman.com/phpgraphlib/documentation/tutorial-mysql-and-phpgraphlib。我运行了我的代码,但它显示了被破坏的图像。我想从数据库中获取数据并生成折线图。我下载了phpgraphlib和libgd包。我还在htdocs和pear文件夹中提取了phpgraphlib.php文件,我还在php.ini文件中找到了php_gd2.dll未注释(没有分号)。

graph.php

  <?php

      include("phpgraphlib.php");
      $graph=new PHPGraphLib(400,300);

      //connection to MySQL database

      $link =mysql_connect('localhost','root','') or die('Could not connect :'. mysql_error());

     //select db
     mysql_selected_db('mynewdb') or die('Could not select database');

     $dataArray=array();

     //get data from database
     $sql="SELECT year1,year2,crit FROM scores WHERE sid='13'";
     $result = mysql_query($sql) or die('Query failed: ' . mysql_error());

   if ($result) {
            while ($row = mysql_fetch_assoc($result)) {
             $crit=$row["crit"];
             $year1=$row["year1"];
             $year2=$row["year2"];
             $count=$row["count"];
            //add to data array
            $dataArray[$crit]=$count;
            }
   }

     //configure graph
      $graph->addData($dataArray);
      $graph->setTitle("Interesting Semester");
      $graph->addData($dataArray);
      $graph->setBars(false);
      $graph->setDataPoints(true);
      $graph->setDataPointColor('maroon');
      $graph->setDataValues(true);
      $graph->setDataValueColor('maroon');
      $graph->setGoalLine(.0025);
      $graph->setGoalLineColor('red');
      $graph->createGraph();

 ?>

0 个答案:

没有答案