Chapter 4. PHPlot Advanced Topics
Prev | Part I. PHPlot Programming | Next

## Chapter 4. PHPlot Advanced Topics

This chapter documents advanced PHPlot programming topics, going beyond the material in Chapter 3, PHPlot Concepts.

## 4.1. Custom PHPlot Class

This section describes how to create a custom PHPlot class.

If you have a number of applications that use PHPlot, and you want to standardize some of the PHPlot default settings, you can define your own class which extends the PHPlot class and changes the default settings. Here is a short example of a custom PHPlot class, which changes the following defaults:

- Use a TrueType font for all text

- Change the default image size to 800 x 600

- Change the default title colors to red

To extend the PHPlot class, declare your class as shown below. Make sure your class constructor calls the PHPlot class constructor before changing any settings.

    <?php
    # Define a custom PHPlot class

    // Load the PHPlot class first
    require_once 'phplot.php';

    // Define a class which extends PHPlot:
    class my_phplot extends PHPlot {
      function __construct($width=800, $height=600, $out=NULL, $in=NULL)
      {
        parent::__construct($width, $height, $out, $in);
        $this->SetDefaultTTFont('LiberationSans-Bold'); // System dependent
        $this->SetTitleColor('red');
      }
    }

To use this custom PHPlot class, use `require_once` to include the file containing the class definition, then create an instance of the custom class.

    $plot = new my_phplot();

You can then use the `$plot` object exactly the same as you might use any other PHPlot object.

Prev | Up | Next
3.9. Error Handling | Home | 4.2. PHPlot Object Serialization