2.4. Different Size Images and Titles

Let's say we want our plot to be bigger, 800 pixels wide and 600 pixels high. So instead of having the line

  $plot = new PHPlot;
  

We replace it with

  $plot = new PHPlot(800,600);
  

and you have specified the size in pixels of the image to be created.

A couple of things to note:

OK, now we're ready to add some customization to the plot. Let's change the size, the title and the X/Y axis labels. All we need to do is use additional methods of the $plot object before printing the image. Here is the complete result:

<?php
//Include the code
require_once 'phplot.php';

//create a PHPlot object with 800x600 pixel image
$plot = new PHPlot(800,600);

//Define some data
$example_data = array(
     array('a',3),
     array('b',5),
     array('c',7),
     array('d',8),
     array('e',2),
     array('f',6),
     array('g',7)
);
$plot->SetDataValues($example_data);

//Set titles
$plot->SetTitle("A Simple Plot\nMade with PHPlot");
$plot->SetXTitle('X Data');
$plot->SetYTitle('Y Data');

//Turn off X axis ticks and labels because they get in the way:
$plot->SetXTickLabelPos('none');
$plot->SetXTickPos('none');

//Draw it
$plot->DrawGraph();

And that's it! What we get is the following graph:

Line graph with titles and labels

Note that the newline character "\n" separates multiple lines in titles, and you must use double quotes around the title string for PHP to recognize the newline.