Jump to content

JPGraph Error - Don't know why


Recommended Posts

hi!

 

I am trying to build a grouped bar graph with JPGraph and it's giving me the standard "The image “http://localhost/testgraphs.php” cannot be displayed, because it contains errors." and

I don't know why.  Anyone?  I've included all code except the $_SESSION variables.  The important ones are explained in the weird comments I've made.

 

<?php
session_start();
include ("jpgraph/jpgraph.php");
include ("jpgraph/jpgraph_bar.php");
include ("jpgraph/jpgraph_line.php");
include ("jpgraph/jpgraph_iconplot.php");
require_once("jpgraph/jpgraph_date.php"); 



$graphWidth = $_SESSION['graphWidth'];
$graphHeight = $_SESSION['graphHeight'];


function TimeCallback($aVal)
{

    	return Date('',strtotime($aVal));
}

$account = $_SESSION['account'];
$monthData = $_SESSION['arr_temps_by_month'];



//print_r($monthData);
foreach($monthData as $aValue){
	//print_r($aValue);
	$year = $aValue['startingYear'];
	$month = intval(date('m',strtotime($aValue['startingYearMonth'])));
	$ydata[$year][$month] = $aValue['monthUsage'];
	//echo "<br>";
}unset($aValue);

//$ydata: this is the best format ive got yet!  its a 2d array with $ydata[$year][$month] = monthusage BEST 4:45 PM 6-25

foreach ($ydata as $data)
{
	if (!$data['1'])
	{
		$data['1'] = 0;		
	}

	if (!$data['2'])
	{
		$data['2'] = 0;		
	}

	if (!$data['3'])
	{
		$data['3'] = 0;		
	}		

	if (!$data['4'])
	{
		$data['4'] = 0;		
	}

	if (!$data['5'])
	{
		$data['5'] = 0;		
	}

	if (!$data['6'])
	{
		$data['6'] = 0;		
	}

	if (!$data['7'])
	{
		$data['7'] = 0;		
	}

	if (!$data['8'])
	{
		$data['8'] = 0;		
	}

	if (!$data['9'])
	{
		$data['9'] = 0;		
	}		

	if (!$data['10'])
	{
		$data['10'] = 0;		
	}

	if (!$data['11'])
	{
		$data['11'] = 0;		
	}

	if (!$data['12'])
	{
		$data['12'] = 0;		
	}

	ksort($data);
	//print_r($data);
	$ydataClean[]=$data; 			//this is now $ydataClean[0][01]=monthusage etc.  it removes starting year.  BESTTTTT 5:09 pm 6-25



	//echo "<br>";
}unset($data);

//print_r($ydataClean);

for($num=0;$num<count($ydataClean);$num++)
{
	$bplot[$num] = new BarPlot($ydataClean[$num]);
  		//$bplot[$num]->SetFillColor([$i]);
  		//$bplot[$num]->SetLegend($groupU[$i]); 	
}unset($num);
$gbarplot = new GroupBarPlot($bplot);

$months=$gDateLocale->GetShortMonth();
// Create the graph. 
$graph = new Graph($graphWidth,$graphHeight);

$graph->SetScale("textlin",0,100);


// Add the plots to the graph
$graph->Add($gbarplot);


$graph->title->Set("Total Monthly Use");
$graph->title->Align("center");
$graph->xaxis->SetTitle("","center");
$graph->yaxis->title->Set("");
$gbarplot->SetWidth(0.;

$graph->legend->SetFont(FF_ARIAL,FS_NORMAL,;

$graph->title->SetFont(FF_ARIAL,FS_BOLD,15);
$graph->yaxis->title->SetFont(FF_ARIAL,FS_BOLD,12);
$graph->xaxis->title->SetFont(FF_ARIAL,FS_BOLD,12);
$graph->yaxis->SetFont(FF_FONT1,FS_NORMAL,;
$graph->xaxis->SetFont(FF_FONT1,FS_NORMAL,;


$icon = new IconPlot('logo_med.gif',$graphWidth/2,$graphHeight/2.2,$graphHeight/400,40);
$icon->SetAnchor('center','center');
$graph->Add($icon);
$graph->Stroke();

//$fileName = "downloads/testgraphs_".$account.".png";
//$graph->img->Stream($fileName);

//$graph->img->Headers();
//$graph->img->Stream();

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/112031-jpgraph-error-dont-know-why/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.