【问题标题】:Jpgraph issue wih the Y axisY轴的Jpgraph问题
【发布时间】:2014-06-08 01:04:39
【问题描述】:

我正在尝试为我的数据库值提供图形输出。问题是 Y 轴似乎无法从我的数据库中接受我的文本值,而我能够在 x 轴上轻松地显示它。 .

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

require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_line.php');

$host = "localhost";
$username = "root";
$password = "";
$database = "cmsd";

$connection=mysql_connect ($host, $username, $password);
if (!$connection) {
die('Not connected : ' . mysql_error());
}
// Set the active mySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}

$sql = mysql_query("SELECT * FROM cmsd1")or die(mysql_error());

while($row = mysql_fetch_array($sql))
{
$data1[] = $row[1];
$data2[] = $row[5];
$data3[] = $row[4];
}
// Setup the graph
$graph = new Graph(1000,600);
$graph->SetScale("textlin");
$nx = count($data2);

$graph->title->Set('Coconut Allele Comparison');
$graph->SetBox(false);

$graph->xaxis->HideZeroLabel();
$graph->xaxis->HideLine(true);
$graph->yaxis->HideZeroLabel(); 
$graph->yaxis->HideFirstTicklabel();
$graph->xaxis->HideTicks(false,false);
$graph->yaxis->HideLine();
$graph->yaxis->SetTickLabels($data1);
$graph->yaxis->SetPos('min');
$graph->xaxis->SetPos('min');
$graph->xgrid->SetFill(false);


$p1 = new LinePlot($data2);
$graph->Add($p1);

$p2 = new LinePlot($data3);
$graph->Add($p2);



$p1->SetColor("white");
$p1->mark->SetType(MARK_SQUARE,'',1.0);
$p1->mark->SetWidth(12);
$p1->mark->SetWeight(4);
$p1->mark->SetCallback("FCallback"); 




function FCallback($aVal) {
// This callback will adjust the fill color and size of
// the datapoint according to the data value according to
    if( $aVal == 180 ) $c = "yellow";
    elseif($aVal > 180) $c = "red";
    else $c= "green";
     return array("",$c,"");
}




$p2->SetColor("white");
$p2->mark->SetType(MARK_SQUARE,'',1.0);
$p2->mark->SetWidth(12);
$p2->mark->SetWeight(4);
$p2->mark->SetCallback("FCallback"); 
$p2->value->SetMargin(14);
$p2->SetCenter();


// Output line
$graph->Stroke();

?>

X 轴显示文本值

Y 轴只显示第一个值,然后给出数字

有什么方法可以在 Y 轴上显示文本值,就像在 x 轴上轻松显示一样。感谢任何帮助

【问题讨论】:

    标签: php database graph jpgraph


    【解决方案1】:

    这是因为它是一个线图。我将其更改为散点图并修复了它。

    【讨论】:

      猜你喜欢
      • 2013-04-29
      • 2017-04-03
      • 2012-09-06
      • 2014-03-06
      • 1970-01-01
      • 2018-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多