private function get_axis($type, $index, $createifnotexists) {
        $isx = $type === 'x';
        if ($isx) {
            $axis = isset($this->xaxes[$index]) ? $this->xaxes[$index] : null;
        } else {
            $axis = isset($this->yaxes[$index]) ? $this->yaxes[$index] : null;
        }

        if ($axis === null) {
            if (!$createifnotexists) {
                throw new coding_exception('Unknown axis.');
            }

            $axis = new chart_axis();
            if ($isx) {
                $this->set_xaxis($axis, $index);
            } else {
                $this->set_yaxis($axis, $index);
            }
        }

        return $axis;
    }