98 |
- |
1 |
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
|
|
|
2 |
<!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>2.4. Different Size Images and Titles</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="starting.html" title="Chapter 2. Getting Started with PHPlot" /><link rel="prev" href="starting-simple.html" title="2.3. A Simple Graph" /><link rel="next" href="start-multiple.html" title="2.5. Multiple Lines Per Graph" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">2.4. Different Size Images and Titles</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="starting-simple.html">Prev</a> </td><th width="60%" align="center">Chapter 2. Getting Started with PHPlot</th><td width="20%" align="right"> <a accesskey="n" href="start-multiple.html">Next</a></td></tr></table><hr /></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="starting-more"></a>2.4. Different Size Images and Titles</h2></div></div></div><p>
|
|
|
3 |
Let's say we want our plot to be bigger, 800 pixels wide and 600 pixels high.
|
|
|
4 |
So instead of having the line
|
|
|
5 |
</p><pre class="programlisting">$plot = new PHPlot;
|
|
|
6 |
</pre><p>
|
|
|
7 |
</p><p>
|
|
|
8 |
We replace it with
|
|
|
9 |
</p><pre class="programlisting">$plot = new PHPlot(800,600);
|
|
|
10 |
</pre><p>
|
|
|
11 |
and you have specified the size in pixels of the image to be created.
|
|
|
12 |
</p><p>
|
|
|
13 |
A couple of things to note:
|
|
|
14 |
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
|
|
|
15 |
The default is not to use TrueType fonts.
|
|
|
16 |
</p></li><li class="listitem"><p>
|
|
|
17 |
Since there was only one graph on the image, we didn't have to
|
|
|
18 |
use PrintImage. DrawGraph took care of it for us.
|
|
|
19 |
</p></li><li class="listitem"><p>
|
|
|
20 |
We did not specify the data type. If you do not specify the data
|
|
|
21 |
type, PHPlot assumes <code class="literal">text-data</code>.
|
|
|
22 |
</p></li><li class="listitem"><p>
|
|
|
23 |
We did not specify the file type (GIF, PNG, JPEG, ...).
|
|
|
24 |
PHPlot 5.0 (and newer) makes PNG images by default.
|
|
|
25 |
</p></li><li class="listitem"><p>
|
|
|
26 |
The data is passed in as an array of arrays. This may seem awkward
|
|
|
27 |
now, but as we add functionality this will be beneficial.
|
|
|
28 |
</p></li></ul></div><p>
|
|
|
29 |
</p><p>
|
|
|
30 |
OK, now we're ready to add some customization to the plot. Let's change
|
|
|
31 |
the size, the title and the X/Y axis labels. All we need to do is use
|
|
|
32 |
additional methods of the <code class="literal">$plot</code> object before
|
|
|
33 |
printing the image. Here is the complete result:
|
|
|
34 |
|
|
|
35 |
</p><pre class="programlisting"><?php
|
|
|
36 |
//Include the code
|
|
|
37 |
require_once 'phplot.php';
|
|
|
38 |
|
|
|
39 |
//create a PHPlot object with 800x600 pixel image
|
|
|
40 |
$plot = new PHPlot(800,600);
|
|
|
41 |
|
|
|
42 |
//Define some data
|
|
|
43 |
$example_data = array(
|
|
|
44 |
array('a',3),
|
|
|
45 |
array('b',5),
|
|
|
46 |
array('c',7),
|
|
|
47 |
array('d',8),
|
|
|
48 |
array('e',2),
|
|
|
49 |
array('f',6),
|
|
|
50 |
array('g',7)
|
|
|
51 |
);
|
|
|
52 |
$plot->SetDataValues($example_data);
|
|
|
53 |
|
|
|
54 |
//Set titles
|
|
|
55 |
$plot->SetTitle("A Simple Plot\nMade with PHPlot");
|
|
|
56 |
$plot->SetXTitle('X Data');
|
|
|
57 |
$plot->SetYTitle('Y Data');
|
|
|
58 |
|
|
|
59 |
//Turn off X axis ticks and labels because they get in the way:
|
|
|
60 |
$plot->SetXTickLabelPos('none');
|
|
|
61 |
$plot->SetXTickPos('none');
|
|
|
62 |
|
|
|
63 |
//Draw it
|
|
|
64 |
$plot->DrawGraph();
|
|
|
65 |
</pre><p>
|
|
|
66 |
|
|
|
67 |
</p><p>
|
|
|
68 |
|
|
|
69 |
And that's it! What we get is the following graph:
|
|
|
70 |
|
|
|
71 |
</p><div class="informalfigure"><div class="mediaobject"><img src="examples/qs2.png" alt="Line graph with titles and labels" /></div></div><p>
|
|
|
72 |
</p><p>
|
|
|
73 |
Note that the newline character "\n" separates multiple lines
|
|
|
74 |
in titles, and you must use double quotes around the title string for PHP
|
|
|
75 |
to recognize the newline.
|
|
|
76 |
</p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="starting-simple.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="starting.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="start-multiple.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">2.3. A Simple Graph </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 2.5. Multiple Lines Per Graph</td></tr></table></div></body></html>
|