Subversion Repositories cheapmusic

Rev

Blame | Last modification | View Log | RSS feed

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><title>Chapter 2. Getting Started with PHPlot</title><link rel="stylesheet" type="text/css" href="phplotdoc.css" /><meta name="generator" content="DocBook XSL Stylesheets V1.78.1" /><link rel="home" href="index.html" title="PHPlot Reference Manual" /><link rel="up" href="part1.html" title="Part I. PHPlot Programming" /><link rel="prev" href="install-next.html" title="1.3. Next Step" /><link rel="next" href="starting-create.html" title="2.2. Creating the Object" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 2. Getting Started with PHPlot</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="install-next.html">Prev</a> </td><th width="60%" align="center">Part I. PHPlot Programming</th><td width="20%" align="right"> <a accesskey="n" href="starting-create.html">Next</a></td></tr></table><hr /></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="starting"></a>Chapter 2. Getting Started with PHPlot</h2></div></div></div><div class="abstract"><p class="title"><strong></strong></p><p>
This chapter will help you get started with PHPlot.
  </p><p>
The material in this chapter was originally from the PHPlot Quick Start
and Examples document, by Afan Ottenheimer and Miguel de Benito,
distributed with PHPlot. It has undergone much editing and any mistakes
are not their fault.
  </p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="starting-intro"></a>2.1. Introduction</h2></div></div></div><p>
Many web sites need to create real-time or dynamic charts and graphs from
live data sets. Many users have found PHP a great way for this dynamic
creation of images using the <a class="link" href="concepts.html#def-gd">GD</a> library. 
The advantage of using the server to create an image (that is, using a
server-side scripting language rather than a client-side language such as
Java) is that one does not have to worry about browser compatibility or
client operating system compatibility issues.
</p><p>
PHPlot is a specialized graphics library which provides a means for your
PHP-enabled web server to create and manipulate graphs as objects and
display the completed graph as an image.
PHPlot uses the GD library to create elementary shapes such as lines,
rectangles, and text, but hides the details of GD from the application
programmer.
</p><p>
Data sets are passed to PHPlot using PHP arrays, in a convenient format
for database-driven sites.
</p><p>
First, lets discuss how PHPlot works in general with some terminology.
(More complete definitions can be found in <a class="xref" href="concepts.html#conc-defs" title="3.1. Definitions">Section 3.1, &#8220;Definitions&#8221;</a>.)
A PHPlot <span class="emphasis"><em>image</em></span> can consist of several
<span class="emphasis"><em>graphs</em></span> (but usually has only one), each graph consisting
of several <span class="emphasis"><em>elements</em></span> (like lines, axes, and labels).
</p><p>
To use PHPlot, you create a PHP object from the PHPlot class, for example:
</p><pre class="programlisting">$plot = new PHPlot;
</pre><p>
Then you set the properties of the object, by using a series of function
calls (actually methods of the class). These define the characteristics of
the image, the graph or graphs, and their elements.  This includes setting
the array containing the data to be plotted, defining titles if you want
them, and many optional elements and style settings.  You can think of this
as "drawing" elements into the image, but in fact PHPlot just notes your
intentions and doesn't do much until you are finished.
</p><p>
When you are done describing a graph, you instruct PHPlot to "draw" the
graph into the image. When you are done with all graphs in an image,
you need to instruct PHPlot to "print" (output) the image.
Since most images contain only one graph, PHPlot simplifies
this process by default. Unless instructed otherwise, PHPlot will "print"
the image (output it to the browser) as soon as you tell it to "draw"
(render) the first graph.
</p><p>
Usually, PHPlot will "print" the image directly to the user's browser.
The result will be a complete HTTP response with headers, so your PHP
script must not produce any other output (except for optional headers).
The user will be see the image either as a result of accessing your
script directly with a URL, like
<code class="literal">http://www.example.com/graphs/myplot.php</code>,
or you can embed the image in a web page using an image tag, like this:
</p><pre class="screen">&lt;IMG SRC="http://www.example.com/graphs/myplot.php"&gt;
</pre><p>
</p><p>
Instead of sending the image to the browser, your application can instead
choose to write the PHPlot image to a file on the server.  This could be
useful if you want to implement server-side caching of image files.
(PHPlot itself does not currently provide caching.)
</p><p>
Before continuing, we need to mention coordinates.
PHPlot uses two coordinate spaces: one for the image, and one for the
data you are plotting.
<span class="emphasis"><em>World Coordinates</em></span>
are the X,Y coordinates of your data, relative to the axis origin,
in the units of the data sets.
Your data array uses world coordinates, as do tick mark labels on the X and
Y axis.
<span class="emphasis"><em>Device Coordinates</em></span>
measure pixels in the image according the the GD convention, with
the origin in the upper left corner of the image. These are also
called Pixel Coordinates.
PHPlot tries to place elements on your graph appropriately, but if
you need to override its choices you will use device coordinates to
position the elements.
</p><p>
The rest of this chapter explains how to write a PHP script which creates
a plot using PHPlot.
Information on PHP can be found at
<a class="ulink" href="http://www.php.net/" target="_top">www.php.net</a>.
Information about the GD library which PHP uses to create images can
be found at <a class="ulink" href="http://libgd.org/" target="_top">libgd.org</a>.
More information about PHPlot can be found at
<a class="ulink" href="http://phplot.sourceforge.net/" target="_top">phplot.sourceforge.net</a>.
</p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="install-next.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="part1.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="starting-create.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">1.3. Next Step </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 2.2. Creating the Object</td></tr></table></div></body></html>