2014-04-23 145 views
0

我想給我的數據庫值的圖形輸出..問題是,Y軸似乎不能接受我的數據庫中的文本值,而我能夠顯示它容易在x軸上..Jpgraph問題與Y軸

<?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軸值

X axis displaying the points

Y軸只顯示所述第一值和然後給數字

Y axis just auto-scaling and not displaying the values

有什麼辦法來軸線以同樣的方式顯示在Y文本值,因爲它很容易在x軸上顯示..任何幫助表示讚賞

回答

0

這是因爲它是一個線圖。我將其改爲散點圖,並將其修正。