Jpgraph问题与Y轴

时间:2014-04-23 09:28:59

标签: php database graph jpgraph

我正在尝试为我的数据库vales提供图形输出..问题是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轴

X axis displaying the points

Y轴仅显示第一个值,然后显示数字

Y axis just auto-scaling and not displaying the values

有没有办法在Y轴上以与在x轴上轻松显示的方式相同的方式显示文本值..感谢任何帮助

1 个答案:

答案 0 :(得分:0)

这是因为这是一个线条图。我把它改成了散点图,我把它修好了。

相关问题