TeeChartPHP
[ class tree: TeeChartPHP ] [ index: TeeChartPHP ] [ all elements ]

Source for file Variance.php

Documentation is available at Variance.php

  1. <?php
  2.  
  3. /**
  4. *
  5. * <p>Title: Variance class</p>
  6. *
  7. * <p>Description: Variance function.</p>
  8. *
  9. * <p>Example:
  10. * <pre><font face="Courier" size="4">
  11. * $function = Variance();
  12. * $function->setChart($myChart->getChart());
  13. * $function->setPeriod(0); //all points
  14. *
  15. * $functionSeries = new Line($myChart->getChart());
  16. * $functionSeries->setTitle("Variance");
  17. * $functionSeries->setDataSource($series);
  18. * $functionSeries->setVerticalAxis(VerticalAxis::$RIGHT);
  19. * $functionSeries->setFunction($function);
  20. * </font></pre></p>
  21. *
  22. * <p>Copyright (c) 2005-2008 by Steema Software SL. All Rights
  23. * Reserved.</p>
  24. *
  25. * <p>Company: Steema Software SL</p>
  26. *
  27. */
  28.  
  29. class Variance extends Functions
  30. {
  31.  
  32.     // Interceptors
  33.     function __get$property {
  34.       $method ="get{$property}";
  35.       if method_exists$this$method ) ) {
  36.         return $this->$method();
  37.       }
  38.     }
  39.  
  40.     function __set $property,$value {
  41.       $method ="set{$property}";
  42.       if method_exists$this$method ) ) {
  43.         return $this->$method($value);
  44.       }
  45.     }
  46.  
  47.    /**
  48.    * Performs function operation on s series.
  49.    *
  50.    * @param Series
  51.    * @param firstIndex int
  52.    * @param lastIndex int
  53.    * @return double 
  54.    */
  55.    public function calculate($s$firstIndex$lastIndex)
  56.    {
  57.       if($firstIndex == - 1)
  58.       {
  59.          $firstIndex 0;
  60.       }
  61.       if($lastIndex == - 1)
  62.       {
  63.          $lastIndex $s->getCount(1;
  64.       }
  65.  
  66.       $count $lastIndex $firstIndex 1;
  67.  
  68.       if($count 0)
  69.       {
  70.          $mean $s->getMandatory()->getTotal($count;
  71.  
  72.          if($count != $s->getCount())
  73.          {
  74.             $mean 0.0;
  75.  
  76.             for($t $firstIndex$t <= $lastIndex$t++)
  77.             {
  78.                $mean += $s->getMandatory()->value[$t];
  79.             }
  80.             $mean /= $count;
  81.          }
  82.  
  83.          $sum 0;
  84.          for($t $firstIndex$t <= $lastIndex$t++)
  85.             $sum += ($s->getMandatory()->value[$t$mean($s->getMandatory()->value[$t$mean);
  86.  
  87.          return $sum $count;
  88.       }
  89.       else
  90.       {
  91.          return 0;
  92.       }
  93.    }
  94.  
  95.    /**
  96.    * Performs function operation on all sourceSeries series.
  97.    *
  98.    * @param sourceSeries ArrayList
  99.    * @param valueIndex int
  100.    * @return double 
  101.    */
  102.    public function calculateMany($sourceSeries$valueIndex)
  103.    {
  104.       $count sizeof($sourceSeries);
  105.       if($count 0)
  106.       {
  107.          $mean 0.0;
  108.          for($t 0$t $count$t++)
  109.          {
  110.             $tmpSeries $sourceSeries->offsetget($t);
  111.             $mean += $tmpSeries->getMandatory()->value[$valueIndex];
  112.          }
  113.          $mean /= $count;
  114.  
  115.          $sum 0.0;
  116.          for($t 0$t $count$t++)
  117.          {
  118.             $tmpSeries $sourceSeries->offsetget($t);
  119.             $sum += sqr($tmpSeries->getMandatory()->value[$valueIndex-
  120.             $mean);
  121.          }
  122.  
  123.          return $sum $count;
  124.  
  125.       }
  126.       else
  127.       {
  128.          return 0.0;
  129.       }
  130.    }
  131.  
  132.    /**
  133.    * Gets descriptive text.
  134.    *
  135.    * @return String 
  136.    */
  137.    public function getDescription()
  138.    {
  139.       return Language::getString("FunctionVariance");
  140.    }
  141. }
  142. ?>

Documentation generated on Wed, 16 Jun 2010 12:09:10 +0200 by phpDocumentor 1.4.1