我是jpgraph的新手,我试图通过从mysql数据库中选择两个字段来显示使用它的线图。但是我遇到了一个问题,因为它找不到我下载的jpgraph文件的目录,问题在我的php文件的顶部。这是错误。

 我将对如何执行此操作提供一些指导。这是我的代码。

谢谢。

<?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();

?>

最佳答案

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

关于php - 使用mysql数据显示JPGraph,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29120915/

10-10 23:37