Jump to content

image_graph in a function


me1000

Recommended Posts

Hi,

 

(all of this is using the PEAR library image_graph http://pear.php.net/package/Image_Graph )

 

I have a file where I need to create several different graphs all the same kind with limited redundancy. So I have created a function where I pass an array of data through it to create the graph.

 

this is what I have that generates the file,

 

function makePieChart($data){


require_once 'Image/Graph.php'; 


// create the graph 
$Graph =& Image_Graph::factory('graph', array(400, 300)); 

// create the plotarea 
$Graph->add( 
Image_Graph::vertical( 
Image_Graph::factory('title', array('OnDemand Overall Status', 12)), 
Image_Graph::horizontal( 
$Plotarea = Image_Graph::factory('plotarea'), 
$Legend = Image_Graph::factory('legend'), 
70 
), 
5 
) 
); 

$Legend->setPlotarea($Plotarea); 

// create the 1st dataset 

$Dataset1 =& Image_Graph::factory('dataset'); 



foreach($data as $value){
$Dataset1->addPoint($value['name'], $value['number']);
} // this gets the $data array from the PDF file, and loops it to create 


$Graph->done(array('filename' => 'output.png'));

}

 

 

 

 

 

 

 

 

I took out a lot of stuff from it, because I didnt see a need to post it but it works in generating a file.

 

 

now here is the problem,

 

when I call the function from another file with this code,

 

 

 

 

include("charts.php");
makePieChart($data)

;

 

 

 

it gives me an error, saying the headers were already sent. So the script is making the php file act as a png correct?

is there a way so that when I call up the function it just creates the new output.png file?

 

 

Thanks,

Link to comment
Share on other sites

I believe it is $Graph->add() which sends the headers, Ill check tomorrow for sure, but Im about 95% sure graph.php is just a bunch of classes in which you must call in order for anything to execute.

 

however the header must be sent sometime to create the PNG... right?

 

Link to comment
Share on other sites

I'm not thoroughly educated in this area, as I have never worked with it before so excuse my possible ignorance...

 

Does the image_draw function require the GD library, or any other libraries for that matter to be enabled?

Link to comment
Share on other sites

ok, the code works now, I just coped the whole charts.php page into the page that was including it which brings me to my next question.

 

Can you not send arrays through a function? for example if my array were,

 

$data['1]=123;

$data['2]=456;

$data['3]=789;

 

and I send $data through the function

 

functionName($data);

 

EDIT: nevermind, because I am still sending the array data through the function!

I really have no idea what was going on...

 

does that not work?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.