javascript – JPGraph (php) line plot – problems with scale-ThrowExceptions

Exception or error:

I am trying to create a line graph using jpgraph.

I am having a problem displaying the graph – the error message I have received is: “JPGraph Error: 25044 = Cannot use auto scaling since it is impossible to determine a valid min/max value of the y axis (only null values).”

My code is below:

<?php // content="text/plain; charset=utf-8"
session_start();
require_once ('../includes/jpgraph/src/jpgraph.php');
require_once ('../includes/jpgraph/src/jpgraph_line.php');
// Some data
$datay1 = $_SESSION['userValues'];
$d = array();
for($i = 0; $i < 30; $i++) 
    $d[] = date("d", strtotime('-'. $i .' days'));

// Create the Line Graph. 
$graph = new Graph(300,250);
$graph->SetScale("textlin");

$theme_class=new UniversalTheme;

$graph->SetTheme($theme_class);
$graph->img->SetAntiAliasing(false);
$graph->title->Set('Your Performance:');
$graph->SetBox(false);

$graph->img->SetAntiAliasing();

$graph->yaxis->HideZeroLabel();
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);

$graph->xgrid->Show();
$graph->xgrid->SetLineStyle("solid");
$graph->xaxis->SetTickLabels($d);
$graph->xgrid->SetColor('#E3E3E3');

// Create the first line
$p1 = new LinePlot($datay1);
$graph->Add($p1);
$p1->SetColor("#6495ED");
$p1->SetLegend('Line 1');

$graph->legend->SetFrameWeight(1);

// Output line
$graph->Stroke();

?>

I think I may have gone wrong with assigning the dates for the x axis (I want to show the last 30 days). The data is passed over using sessions and have tested to ensure that this contains the actual data.

Thanks

How to solve:

Try to do the following and have a look at that webpage http://jpgraph.net/doc/howto2.php

As usual we want to make sure that the scale of the X-axis covers our
function exactly so we need to find out the min and max values along
the X-axis and use them to manually set the scale.

$n = count($datax);
$xmin = $datax[0];
$xmax = $datax[$n-1];

It’s now time to setup the basic graph. This is very similair to waht
we did before with the only difference that we use the
SetMajtickPosition() method to avoid a NULL argument for the minor
ticks which we are not interested in.

$graph->SetScale('linlin',0,0,$xmin,$xmax);
$graph->title->Set('Example with manual tick labels');
$graph->title->SetFont(FF_ARIAL,FS_NORMAL,12);
$graph->xaxis->SetPos('min');
$graph->xaxis->SetMajTickPositions($tickPositions,$tickLabels);
$graph->xaxis->SetFont(FF_TIMES,FS_NORMAL,10);
$graph->yaxis->SetFont(FF_TIMES,FS_NORMAL,10);
$graph->xgrid->Show();

Leave a Reply

Your email address will not be published. Required fields are marked *