【问题标题】:Display JPGraph using mysql data使用mysql数据显示JPGraph
【发布时间】:2015-05-21 04:04:34
【问题描述】:

我是 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();

?> 

【问题讨论】:

    标签: php mysql jpgraph


    【解决方案1】:

    先将你的jpgraph-3.5.0b1.tar.gz文件解压到某个目录下,然后你就可以对这个目录使用require函数了。

    【讨论】:

      猜你喜欢
      • 2013-11-30
      • 2015-03-23
      • 2010-09-20
      • 1970-01-01
      • 1970-01-01
      • 2013-05-07
      • 2013-08-08
      • 2016-11-08
      • 1970-01-01
      相关资源
      最近更新 更多