Hi forums..
This is the first posting here
I want to create graph using jpgraph.
Here the scripts:
<?
require_once("chart/jpgraph.php");
require_once("chart/jpgraph_bar.php");
require_once("chart/jpgraph_date.php");
$DBhost = "localhost";
$DBuser = "root";
$DBpass = "******";
$DBName = "batch";
$table = "online";
$conn=@mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
mysql_select_db($DBName,$conn) or die("Unable to select database $DBName");
$query_ChartRS = "SELECT eoddate, timediff(actmerv2, actmerv) as diff FROM $table where eoddate >= '2006-07-24' AND eoddate <= '2006-10-22' ORDER BY eoddate asc";
$ChartRS = mysql_query($query_ChartRS) or die(mysql_error());
function yLabelFormat( $seconds)
{
$hours = 0;
$minutes = 0;
// $hours = 60;
while ($seconds>3600)
{
$hours++;
$seconds -= 3600;
}
while ($seconds>60)
{
$minutes++;
$seconds -= 60;
}
if ($hours<10)
$hours = '0' . $hours;
if ($minutes<10)
$minutes = '0' . $minutes;
if ($seconds<10)
$seconds = '0' . $seconds;
$timestamp = $hours . ':' . $minutes . ':' . $seconds;
return $timestamp;
}
$datay=array();
$labelx=array();
while ($row_ChartRS = mysql_fetch_array($ChartRS)) {
$labelx[] = $row_ChartRS['eoddate'];
$datay[] = $row_ChartRS['diff'];
}
//var_dump($datay);
//chart size 600x300 pixels
$graph = new Graph(800,300, 'auto');
$graph->SetScale("textlin");
//$graph->yaxis->SetLabelFormatCallback('callDuration');
$graph->yaxis->scale->SetGrace(5);
$graph->img->SetMargin(80,20,30,60);
$graph->SetShadow();
$graph->yaxis->SetLabelFormatCallback('yLabelFormat');
$graph->title->Set("Batch Report");
$graph->yaxis->title->Set("Offline Duration");
$graph->xaxis->title->Set("Date EOD");
$graph->title->SetFont(FF_FONT2, FS_BOLD, 14);
$graph->yaxis->title->SetFont(FF_FONT1, FS_NORMAL,10);
$graph->xaxis->title->SetFont(FF_FONT1, FS_NORMAL, 10);
$bplot = new BarPlot($datay);
$graph->xaxis->SetTickLabels($labelx);
$graph->yaxis->scale->ticks->Set(300,60);
$graph->Add($bplot);
$bplot->SetWidth(5.5);
$bplot->SetFillGradient("navy","#EEEEEE",GRAD_LEFT_REFLECTION);
$bplot->SetShadow();
$bplot->value->Show();
$graph->Stroke();
mysql_free_result($ChartRS);
?>
But It shown the error message like:
JpGraph Error Either X or Y data arrays contains non-numeric values. Check that the data is really specified as numeric data and not as strings. It is an error to specify data for example as '-2345.2' (using quotes).
I tried var_dump($datay)
Bellow is the message:
array(3) { [0]=> string(8) "09:27:00" [1]=> string(8) "09:30:00" [2]=> string(8) "00:10:00" }
I need help from forums to solve this problem
Thanks..