Question

I am trying to give a graph output for my database vales.. the Problem is that Y axis does not seem to be able to accept my text values from my database while I am able to display it easily on the x axis..

<?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 axis displaying the text values

X axis displaying the points

Y axis displaying only the first value and then giving numbers

Y axis just auto-scaling and not displaying the values

Is there any way to display the text values on the Y axis the same way as it was easily displaying on the x axis.. Any help is appreciated

Was it helpful?

Solution

It was because it was a line plot. I changed it to a scatter plot and I got it fixed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top