2014-04-23 89 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

这是因为它是一个线图。我将其改为散点图,并将其修正。