Chapter 31. Creating original themes
| Part VII. Theme Class |

## Chapter 31. Creating original themes

You can create an original theme class yourself. You can easily create new theme classes by extending the 'Theme' class and adding your own settings.

Let's say that you like 'AquaTheme' but want to make some changes. In 'AquaTheme', the y axis and y scale are not displayed. To change these settings and to display both, you can use the following. However, it can be time-consuming to add these lines to each graph individually.

    1
    2
    3
    4
    <?php
    $graph->yaxis->HideLine(false);
    $graph->yaxis->HideTicks(false,false);
    ?>

It may be easier to create a new theme based on the original but which has some different settings. Lets create 'MyAquaTheme'. You should put the new theme class file in the 'Theme' folder, This is where all theme classes are kept.

At first, create a file at Themes/MyAquaTheme.class.php. The code for 'MyAquaTheme' class is the following.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    <?php
    class MyAquaTheme extends AquaTheme
    {
      function SetupGraph($graph) {
        parent::SetupGraph($graph);
        $graph->yaxis->HideLine(false);
        $graph->yaxis->HideTicks(false,false);
      }
    }
    ?>

When redefining a method of parent class, please call the parent method. In this way, all settings of the parent class method are applied and you can add the original settings. Font, x axis, y axis colors etc are all defined as class properties. The following code shows how to change these settings.

    1
    2
    3
    4
    5
    6
    7
    8
    <?php
    function __construct() {
        $this->font_color       = '#009900';
        $this->background_color = '#EEFFDD';
        $this->axis_color       = '#00CC00';
        $this->grid_color       = '#33CC33';
    }
    ?>

You can set four properties, $font_color, $background_color, $axs_color and $grid_color. You can also change values individually.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    <?php
    class MyAquaTheme extends AquaTheme
    {
        function __construct() {
            $this->font_color       = '#009900';
            $this->background_color = '#EEFFDD';
            $this->axis_color       = '#00CC00';
            $this->grid_color       = '#33CC33';
        }

        function SetupGraph($graph) {
            parent::SetupGraph($graph);
            $graph->yaxis->HideLine(false);
            $graph->yaxis->HideTicks(false,false);
        }
    }
    ?>

| Up |
| Home |