me1000 Posted March 4, 2008 Share Posted March 4, 2008 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 https://forums.phpfreaks.com/topic/94203-image_graph-in-a-function/ Share on other sites More sharing options...
Northern Flame Posted March 4, 2008 Share Posted March 4, 2008 Does Graph.php send out headers? Link to comment https://forums.phpfreaks.com/topic/94203-image_graph-in-a-function/#findComment-482507 Share on other sites More sharing options...
unsider Posted March 4, 2008 Share Posted March 4, 2008 Does Graph.php send out headers? What he said: something like this: header('Content-type: image/jpeg'); Link to comment https://forums.phpfreaks.com/topic/94203-image_graph-in-a-function/#findComment-482544 Share on other sites More sharing options...
me1000 Posted March 4, 2008 Author Share Posted March 4, 2008 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 https://forums.phpfreaks.com/topic/94203-image_graph-in-a-function/#findComment-482545 Share on other sites More sharing options...
unsider Posted March 4, 2008 Share Posted March 4, 2008 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 https://forums.phpfreaks.com/topic/94203-image_graph-in-a-function/#findComment-482550 Share on other sites More sharing options...
me1000 Posted March 4, 2008 Author Share Posted March 4, 2008 I dont know where you see image_draw() at, but I believe the image_graph class require the GD library... Link to comment https://forums.phpfreaks.com/topic/94203-image_graph-in-a-function/#findComment-483288 Share on other sites More sharing options...
unsider Posted March 4, 2008 Share Posted March 4, 2008 Haha, oops, my mistake, I meant image_graph. And ok, I thought so. Link to comment https://forums.phpfreaks.com/topic/94203-image_graph-in-a-function/#findComment-483314 Share on other sites More sharing options...
me1000 Posted March 5, 2008 Author Share Posted March 5, 2008 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 https://forums.phpfreaks.com/topic/94203-image_graph-in-a-function/#findComment-483439 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.