使用mysql数据显示JPGraph

时间:2015-03-18 11:32:00

标签: php mysql jpgraph

我是jpgraph的新手,我试图通过从我的mysql数据库中选择两个字段来显示使用它的折线图。但是我遇到了一个问题,因为它无法找到我下载的jpgraph文件的目录,问题出在我的php文件的顶部。这是错误。 enter image description here  我会很感激如何做到这一点。这是我的代码。

感谢。

<?php // content="text/plain; charset=utf-8"

define('__ROOT__', dirname(dirname(__FILE__)));
require_once ("e:/xampp/bootstraptable/jpgraph-3.5.0b1.tar.gz/jpgraph1.php");
require_once ("e:/xampp/bootstraptable/jpgraph-3.5.0b1.tar.gz/jpgraph_line.php");
require_once ("e:/xampp/bootstraptable/jpgraph-3.5.0b1.tar.gz/jpgraph_error.php");
//require_once ('../jpgraph.php');
//require_once ('../jpgraph_line.php');
//require_once ('../jpgraph_error.php');


$x_axis = array();
$y_axis = array();
$i = 0;
 $username = "root"; 
    $host = "localhost";
    $database="dairy herd system";

    //set up mysql connection
            mysql_connect("localhost", "root", "") or die(mysql_error());
            //select database
            mysql_select_db("dairy herd system") or die(mysql_error());


   $server = mysql_connect($host, $username);
    $connection = mysql_select_db($database, $server);

    $myquery = "SELECT  `milk_solids`, `tag_number` FROM  `milk` 
";
    $query = mysql_query($myquery);
    if ( ! $query ) {
        echo mysql_error();
        die;
    }

    $data = array();

    for ($x = 0; $x < mysql_num_rows($query); $x++) {
        $data[] = mysql_fetch_assoc($query);
    }

    //echo json_encode($data);     

    while($row = mysqli_fetch_array($myquery)) {
$x_axis[$i] =  $row["tag_number"];
$y_axis[$i] = $row["milk_solids"];
    $i++;

}



    mysql_close($server);





    //mysqli_close($con);



$graph = new Graph(800,500);
$graph->img->SetMargin(40,40,40,40); 
$graph->img->SetAntiAliasing();
$graph->SetScale("textlin");
$graph->SetShadow();
$graph->title->Set("Milk solids produced in herd");
$graph->title->SetFont(FF_FONT1,FS_BOLD);


// Use 20% "grace" to get slightly larger scale then min/max of
// data
$graph->yscale->SetGrace(0);


$p1 = new LinePlot($y_axis);
$p1->mark->SetType(MARK_FILLEDCIRCLE);
$p1->mark->SetFillColor("red");
$p1->mark->SetWidth(4);
$p1->SetColor("blue");
$p1->SetCenter();
$graph->Add($p1);

$graph->Stroke();

?> 

1 个答案:

答案 0 :(得分:0)

首先将jpgraph-3.5.0b1.tar.gz文件解压缩到某个目录中,之后可以在此目录中使用require函数。