# GoogleLineChart.class.php

Go to the documentation of this file.

    00001 <?php
    00002 /***************************************************************************
    00003  *   Copyright (C) 2008-2009 by Denis M. Gabaidulin                        *
    00004  *                                                                         *
    00005  *   This program is free software; you can redistribute it and/or modify  *
    00006  *   it under the terms of the GNU Lesser General Public License as        *
    00007  *   published by the Free Software Foundation; either version 3 of the    *
    00008  *   License, or (at your option) any later version.                       *
    00009  *                                                                         *
    00010  ***************************************************************************/
    00011
    00015     class GoogleLineChart extends GoogleChart
    00016     {
    00017         protected $axesCollection   = null;
    00018         protected $style            = null;
    00019         protected $labelStyle       = null;
    00020
    00024         public static function create()
    00025         {
    00026             return new self;
    00027         }
    00028
    00029         public function __construct()
    00030         {
    00031             parent::__construct();
    00032
    00033             $this->type =
    00034                 new GoogleChartType(GoogleChartType::LINE);
    00035
    00036             $this->color = GoogleChartColor::create();
    00037
    00038             $this->legend =
    00039                 GoogleChartLegend::create()->
    00040                 setPosition(
    00041                     GoogleChartLegendPositionType::create(
    00042                         GoogleChartLegendPositionType::BOTTOM
    00043                     )
    00044                 );
    00045
    00046             $this->data =
    00047                 GoogleChartData::create()->
    00048                 setEncoding(GoogleChartDataTextEncoding::create())->
    00049                 setDataScaling();
    00050
    00051             $this->axesCollection = GoogleChartAxisCollection::create();
    00052
    00053             $this->style = GoogleChartLineStyle::create();
    00054
    00055             $this->labelStyle = GoogleChartLabelStyle::create();
    00056         }
    00057
    00061         public function addLine(GoogleChartLine $line)
    00062         {
    00063             $this->color->addColor($line->getColor());
    00064             $this->legend->addItem($line->getTitle());
    00065             $this->data->addDataSet($line->getValue());
    00066
    00067             if ($style = $line->getStyle())
    00068                 $this->style->addStyle($style);
    00069
    00070             if ($labelStyle = $line->getLabelStyle())
    00071                 $this->labelStyle->addStyle(
    00072                     $labelStyle->setDataSetIndex($this->data->getCount() - 1)
    00073                 );
    00074
    00075             return $this;
    00076         }
    00077
    00081         public function setLegendPosition(GoogleChartLegendPositionType $type)
    00082         {
    00083             $this->legend->setPosition($type);
    00084
    00085             return $this;
    00086         }
    00087
    00091         public function addAxis(GoogleChartAxis $axis)
    00092         {
    00093             $this->axesCollection->addAxis($axis);
    00094
    00095             return $this;
    00096         }
    00097
    00098         public function toString()
    00099         {
    00100             $string = parent::toString();
    00101
    00102             $string .= '&'.$this->axesCollection->toString();
    00103
    00104             if ($this->style->hasStyles())
    00105                 $string .= '&'.$this->style->toString();
    00106
    00107             if ($this->labelStyle->hasStyles())
    00108                 $string .= '&'.$this->labelStyle->toString();
    00109
    00110             return $string;
    00111         }
    00112     }
    00113 ?>