0

I am trying to display a simple graph on my localhost using php graph library . My code is :

include('phpgraphlib.php');
$graph = new PHPGraphLib(650,200);
$data = array("1" => .0032, "2" => .0028, "3" => .0021, "4" => .0033, 
"5" => .0034, "6" => .0031, "7" => .0036, "8" => .0027, "9" => .0024, 
"10" => .0021, "11" => .0026, "12" => .0024, "13" => .0036, 
"14" => .0028, "15" => .0025);
$graph->addData($data);
$graph->setTitle('PPM Per Container');
$graph->setBars(false);
$graph->setLine(true);
$graph->setDataPoints(true);
$graph->setDataPointColor('maroon');
$graph->setDataValues(true);
$graph->setDataValueColor('maroon');
$graph->setGoalLine(.0025);
$graph->setGoalLineColor('red');
$graph->createGraph();

But unfortunately, there is no graph displayed on my screen. I have checked my GD support on phpinfo and it gives me following result

GD Support  enabled
GD Version  bundled (2.1.0 compatible)
FreeType Support    enabled
FreeType Linkage    with freetype
FreeType Version    2.4.10
GIF Read Support    enabled
GIF Create Support  enabled
JPEG Support    enabled
libJPEG Version 8
PNG Support enabled
libPNG Version  1.2.50
WBMP Support    enabled
XPM Support enabled
libXpm Version  30411
XBM Support enabled

My Php version is 5.4.19 ,

What am I doing wrong here ? Please help me

Thanks in advance

2 Answers2

1

It appears that your $data array is numeric. I would suggest creating the array like this instead of creating an associative array:

$data = array(.0032, .0028, .0021, .0033, .0034, .0031, .0036, .0027,
 .0024, .0021, .0026, .0024, .0036, .0028, .0025);

I am running PHP 7.1 on my local machine, and for some reason, PHPGraphLib will not render the graph is I use an associative array for the $data array. PHP 5.4.45 will render the graph with the associative array just fine. It may have something to do with how each version recognizes or internally processes associative arrays.

Greg G
  • 135
  • 1
  • 11
0

Same thing happened to me.. But with php 5.5 it works perfectly.. I just dont understand whats the issue with php 5.4..

oxvoxic
  • 325
  • 2
  • 4
  • 19