Contents
Login Register Wishes Forum About
FAQ » Script output
Help topics
Latest updates
1047d  replaceImageMapTitle
1047d  replaceImageMapValues
1047d  createFunctionSerie
1047d  setAbsicssaPosition
1047d  negateValues
Toolbox
  Download as PDF
  Print this page
  Share this page
  Create an account
  Feed the updates!
Google AdSense
Script output - How to deal with it

There is basically two way to use the output stream of the pChart library.

Rendering to the web browser

The most common way to use this library. Your script are processing real time or archived data and then generate a picture that is sent directly to the user browser. Server side, you‘ll call the stroke() function, client side, you‘ll invoke the script from an <IMG> HTML tag. The whole stuff would be like :

Server Side (mypic.php)
 /* Render the picture (choose the best way) */
 $myPicture->stroke;
Client side (mypage.html)
 <IMG SRC=‘mypic.php‘>

Calling the Stroke() method in your script will automatically send the ‘Content-type: image/png‘ header to the user web browser and the raw picture in the HTTP GET data field.

Rendering to a flat file

This option is often used by scheduled tasks and automatic script that are run on a regular interval and generate a picture that will be access like a standard file from the web server. Those pictures may also be used inside complex documents (PDF, bigger pictures). To render a picture to a file, just invoke the render("myfile.png") function.

Server Side (mypic.php)
 /* Render the picture (choose the best way) */
 $myPicture->render("mypic.png");
Client side (mypage.html)
 <IMG SRC=‘mypic.png‘>

..with this way, the user browser will NOT trigger the picture generation. the mypic.php should be called by another source.

Automatic method choosing

You may have noticed that the examples shipped with the pChart library can either be run from a web browser or the command line. This behavior is possible because of the autoOutput("myfile.png") method. If this method is called from a CLI session then the picture will be rendered to a file. If this method is called from any other type of session, the picture will be sent to the user browser.

Server Side (mypic.php)
 /* Render the picture (choose the best way) */
 $myPicture->autoOutput("mypic.png");
Client side (mypage.html)
 <IMG SRC=‘mypic.php‘>

..if mypic.php is called from the IMG tag, the picture will be sent to the browser. If it is called from a CLI interface, a file named mypic.png will be created.
Last updated on 12/06/2010 
by Jean-Damien 
Linked resources
  There is no linked topic yet.
Community comments
Message from BG on 24/02/2011
I‘m having issues with the stroke function. According to the documentation, I should be able to use $myPicture->stroke, then invoke that script using <img> tags. Here is a glance at what I have. Can someone tell me what I am doing wrong. ------------------------------------------------ netsales.php
<?php
 include("../class/pData.class.php");
 include("../class/pDraw.class.php");
 include("../class/pImage.class.php");
/* query net sales and create image */
$myPicture->stroke;
?>

------------------------------------------------ index.php
<?php include ‘netsales.php‘; ?>
<html>
<body>
     <div><img src="netsales.php" /></div>
</body>
</html>
Message from Carapau on 03/03/2011
I have the same problem...
Message from Robert on 16/05/2011
$myPicture->stroke;
is wrong. It should be:
$myPicture->stroke();
(Note the parentheses)
Message from sargrass on 13/07/2011
Have the same problem. Used Stroke() with parenthesis. Got img with broken link (img with red cross). Can any one help? Thanks a lot.
© Copyrights
Components used on this web site : Famfamfam icons has been made by Mark James, Rounded corners lite has been coded by Cameron Cooke and Tim Hutchison, SyntaxHighlighter has been written by Alex Gorbatchev. pChart and this web site have been created by Jean-Damien POGOLOTTI. This documentation contains 185 pages and 55 comments. 785 users have registered. This page has been rendered in 0,03 seconds. Wiki revision 1.37.