|
Use Pchart on a Server free
Author |
Message |
msryan
pChart user
Joined: Tue Jun 12, 2012 10:08 am Posts: 5
|
Use Pchart on a Server free
I apologise for this simple question.i'm trying to buid some charts for my application. I have just installed pChart (Server Free, PHP5) and have followed all instructions on the web page - but only this error Code: Warning: Cannot modify header information - headers already sent by (output started at /mnt/109/sda/5/8/segula.lsa234/temperature_stat.php:30) in /mnt/109/sda/5/8/segula.lsa234/pImage.class.php on line 166
when i'm trying to use pchart class. GD extension is enabled. Where do I start looking for the problem?
|
Tue Jun 12, 2012 12:50 pm |
|
|
chartbreaker
Experienced pChart user
Joined: Tue Aug 02, 2011 11:49 pm Posts: 34
|
Re: Use Pchart on a Server free
you echoed some output already before the header information was sent by pImage.class.php on line 166 put Code: <?php ob_start(); /* activate output buffering until header() was sent */ ?> in the very first line of your script and Code: <?php ob_end_flush(); /* stop output buffering and echo buffer content */ ?> in the last line of your script
|
Thu Jun 14, 2012 7:23 am |
|
|
msryan
pChart user
Joined: Tue Jun 12, 2012 10:08 am Posts: 5
|
Re: Use Pchart on a Server free
Thanks for reply to my post
but i don't understand very well!!
in which file do i put those lines? in pImage.class.php or in the page where i want the image to be created?
|
Thu Jun 14, 2012 8:22 am |
|
|
chartbreaker
Experienced pChart user
Joined: Tue Aug 02, 2011 11:49 pm Posts: 34
|
Re: Use Pchart on a Server free
into your file in which you also included the pChart classes
explanation: pImage.class.php uses the php header() command before creating the png image
header() can only be used if no content output at all was sent by the server to the client
i think your page does some output before including the pChart classes and before rendering the image
so output buffering as described should be a workaround, because it holds back the complete output till the end of your script
|
Thu Jun 14, 2012 12:00 pm |
|
|
msryan
pChart user
Joined: Tue Jun 12, 2012 10:08 am Posts: 5
|
Re: Use Pchart on a Server free
thx for your help!!! i don't have this error!! but i have another one: Code: l'image "http://segula.lsa234.free.fr/temperature_stat.php" ne peut être affichée car elle contient des erreurs. i don't find my mistake. Here is the code which allows me to create the image: Code: if(isset ($_POST)) { $numeroseriefauteuil=$_POST['numeroserieFauteuil']; $temperature= array();// tableau contenant toutes la valeurs de temperature $time= array(); //tableau conteant les timeStamp correspondant aux temperatures $mabasededonnee="*******"; // test la connection $connection = mysql_connect("******","*****","******"); if ( ! $connection ) die ("connection impossible"); // Connecte la base mysql_select_db($mabasededonnee) or die ("pas de connection" ); // récupération de la période de température enregistrée par le médécin $query="SELECT periodetemp, nomalade FROM DataRegister WHERE numeroserieFaut='$numeroseriefauteuil'"; $result=mysql_query($query); while ($donnees=@mysql_fetch_array($result)) { $nom=$donnees['nomalade']; $periode=$donnees['periodetemp']; } // Récupération des valeurs présentes $query="SELECT temp, date FROM fauteuil WHERE numeroserieFaut='$numeroseriefauteuil'"; $result=mysql_query($query); while ($data=@mysql_fetch_array($result)) { $temperature[]=$data['temp']; $time[]=$data['date']; } /* Create and populate the pData object */ $MyData = new pData(); $MyData->addPoints($temperature,"Probe 1"); $MyData->setAxisName(0,"Temperatures"); $MyData->addPoints($time,"Labels"); $MyData->setSerieDescription("Labels","date"); $MyData->setAbscissa("Labels"); /* Create the pChart object */ $myPicture = new pImage(700,230,$MyData);
/* Draw the background */ $Settings = array("R"=>170, "G"=>183, "B"=>87, "Dash"=>1, "DashR"=>190, "DashG"=>203, "DashB"=>107); $myPicture->drawFilledRectangle(0,0,700,230,$Settings);
/* Overlay with a gradient */ $Settings = array("StartR"=>219, "StartG"=>231, "StartB"=>139, "EndR"=>1, "EndG"=>138, "EndB"=>68, "Alpha"=>50); $myPicture->drawGradientArea(0,0,700,230,DIRECTION_VERTICAL,$Settings); $myPicture->drawGradientArea(0,0,700,20,DIRECTION_VERTICAL,array("StartR"=>0,"StartG"=>0,"StartB"=>0,"EndR"=>50,"EndG"=>50,"EndB"=>50,"Alpha"=>80));
/* Add a border to the picture */ $myPicture->drawRectangle(0,0,699,229,array("R"=>0,"G"=>0,"B"=>0)); /* Write the picture title */ $myPicture->setFontProperties(array("FontName"=>"Silkscreen.ttf","FontSize"=>6)); $myPicture->drawText(10,13,"Temperature du patient: $nom",array("R"=>255,"G"=>255,"B"=>255));
/* Write the chart title */ $myPicture->setFontProperties(array("FontName"=>"Forgotte.ttf","FontSize"=>11)); $myPicture->drawText(250,55,"temperature",array("FontSize"=>20,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
/* Draw the scale and the 1st chart */ $myPicture->setGraphArea(60,60,500,200); $myPicture->drawFilledRectangle(60,60,450,190,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10)); $myPicture->drawScale(array("DrawSubTicks"=>TRUE)); $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); $myPicture->setFontProperties(array("FontName"=>"pf_arma_five.ttf","FontSize"=>6)); $myPicture->drawLineChart(array("DisplayValues"=>TRUE,"DisplayColor"=>DISPLAY_AUTO)); $myPicture->setShadow(FALSE); /* Write the chart legend */ $myPicture->drawLegend(510,205,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));
/* Render the picture (choose the best way) */ $myPicture->autoOutput("temperature_stat.png"); } please can you help me to find the mistake!!! thanks for u'r help!!
|
Fri Jun 15, 2012 7:35 am |
|
|
chartbreaker
Experienced pChart user
Joined: Tue Aug 02, 2011 11:49 pm Posts: 34
|
Re: Use Pchart on a Server free
first error fixed - glad I could help you with it new error No.2: I don't understand French, so I don't know what the error is about, please translate Quote: l'image "http://segula.lsa234.free.fr/temperature_stat.php" ne peut être affichée car elle contient des erreurs.
|
Fri Jun 15, 2012 11:55 am |
|
|
darkspaul
New pChart user
Joined: Tue May 22, 2012 2:12 pm Posts: 1
|
Re: Use Pchart on a Server free
Google trad is your friend. Quote: the image "http://segula.lsa234.free.fr/temperature_stat.php" can not be displayed because it contains errors. i hope you understand this translate, because I'm french too, and my English is bad ( shame on me =/)
|
Fri Jun 15, 2012 2:37 pm |
|
|
chartbreaker
Experienced pChart user
Joined: Tue Aug 02, 2011 11:49 pm Posts: 34
|
Re: Use Pchart on a Server free
are you sure that the $temperature and $time arrays contain correct data? I doubt it. Code: while ($data=@mysql_fetch_array($result)) { $temperature[]=$data['temp']; $time[]=$data['date']; } have a look at the data with Code: echo '<pre>'; print_r($data); print_r($temperature); print_r($time); echo '</pre>';
/* following 2 lines needed after this preliminary output of the arrays only to suppress the rest of the script */
ob_end_flush(); /* because you've set ob_start(); in the very first line of your script */ exit(); /* exit the script here to prevent the image error */ before running pChart functions (please add these few lines after the while-loop and post the results) I think you have to use array_push() to fill the arrays correctly.
|
Sat Jun 16, 2012 9:49 pm |
|
|
msryan
pChart user
Joined: Tue Jun 12, 2012 10:08 am Posts: 5
|
Re: Use Pchart on a Server free
i add the few lines as u say. i have the right informations in my tabs after the while-loop. Code: Array ( [0] => 21 [1] => 40 ) Array ( [0] => 2012-05-29 14:57:46 [1] => 2012-05-29 14:59:38 ) but i can't build my chart!!!
|
Mon Jun 18, 2012 9:01 am |
|
|
chartbreaker
Experienced pChart user
Joined: Tue Aug 02, 2011 11:49 pm Posts: 34
|
Re: Use Pchart on a Server free
ok I've made a test chart with your code (just changed the paths for include-classes and fonts) and your data and the output worked Code: <?php include("../charts/pChart/class/pData.class.php"); include("../charts/pChart/class/pDraw.class.php"); include("../charts/pChart/class/pImage.class.php");
$temperature[] = 21; array_push($temperature, 40); $time[] = '2012-05-29 14:57:46'; array_push($time, '2012-05-29 14:59:38');
/* Create and populate the pData object */ $MyData = new pData(); $MyData->addPoints($temperature,"Probe 1"); $MyData->setAxisName(0,"Temperatures"); $MyData->addPoints($time,"Labels"); $MyData->setSerieDescription("Labels","date"); $MyData->setAbscissa("Labels");
/* Create the pChart object */ $myPicture = new pImage(700,230,$MyData);
/* Draw the background */ $Settings = array("R"=>170, "G"=>183, "B"=>87, "Dash"=>1, "DashR"=>190, "DashG"=>203, "DashB"=>107); $myPicture->drawFilledRectangle(0,0,700,230,$Settings);
/* Overlay with a gradient */ $Settings = array("StartR"=>219, "StartG"=>231, "StartB"=>139, "EndR"=>1, "EndG"=>138, "EndB"=>68, "Alpha"=>50); $myPicture->drawGradientArea(0,0,700,230,DIRECTION_VERTICAL,$Settings); $myPicture->drawGradientArea(0,0,700,20,DIRECTION_VERTICAL,array("StartR"=>0,"StartG"=>0,"StartB"=>0,"EndR"=>50,"EndG"=>50,"EndB"=>50,"Alpha"=>80));
/* Add a border to the picture */ $myPicture->drawRectangle(0,0,699,229,array("R"=>0,"G"=>0,"B"=>0));
/* Write the picture title */ $myPicture->setFontProperties(array("FontName"=>"../charts/pChart/fonts/arial.ttf","FontSize"=>6)); $myPicture->drawText(10,13,"Temperature du patient: $nom",array("R"=>255,"G"=>255,"B"=>255));
/* Write the chart title */ $myPicture->setFontProperties(array("FontName"=>"../charts/pChart/fonts/arial.ttf","FontSize"=>11)); $myPicture->drawText(250,55,"temperature",array("FontSize"=>20,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
/* Draw the scale and the 1st chart */ $myPicture->setGraphArea(60,60,500,200); $myPicture->drawFilledRectangle(60,60,450,190,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10)); $myPicture->drawScale(array("DrawSubTicks"=>TRUE)); $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); $myPicture->setFontProperties(array("FontName"=>"../charts/pChart/fonts/arial.ttf","FontSize"=>6)); $myPicture->drawLineChart(array("DisplayValues"=>TRUE,"DisplayColor"=>DISPLAY_AUTO)); $myPicture->setShadow(FALSE);
/* Write the chart legend */ $myPicture->drawLegend(510,205,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));
/* Render the picture (choose the best way) */ $myPicture->autoOutput("temperature_stat.png"); ?> so the problem must be elsewhere in your code to help you with that, you have to post the complete code I guess it would be better to have a separate file for the charting function instead of integrating the code in the main script you would include this separate file after the database-operations are successfully done so that the charting will be done outside the if(isset ($_POST)) {-expression and only when $temperature and $time contains suitable data, which you can proof also separately and you can try to render the image as a flat png-file and insert a HTML <img> tag in your website to display the output-png thereto you have to use $myPicture->render($imgPathFile); instead of $myPicture->autoOutput("temperature_stat.png"); $imgPathFile contains the the path and filename like '../charts/imgCache/chart1.png' but you have to make sure that the imgCache directory exists and that it is writeable for your script echo '<img id="chart1" src="'.$imgPathFile.'" alt="chart1" border="0">'; should work for the output
Attachments:
forum.php.png [ 19.08 KiB | Viewed 12492 times ]
|
Mon Jun 18, 2012 10:29 am |
|
|
Who is online |
Users browsing this forum: No registered users and 30 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|
|