问题描述:

i am new to jpgraph and im trying to show a line graph using it by selecting two fields from my mysql database. However i have encountered a problem as it cant find the directory to the jpgraph file that i downloaded, the problem is at the top of my php file. Here is the error.

I would appreciate some guidance on how to do this. Here is my code.

Thanks.

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

?>

网友答案:

unzip your jpgraph-3.5.0b1.tar.gz file into some directory first, and after that you can use require function with this directory.

相关阅读:
Top