/**
  * construct multigraph
  */
 public function Values($values)
 {
     parent::Values($values);
     if (!$this->values->error) {
         $this->multi_graph = new MultiGraph($this->values, $this->force_assoc, $this->datetime_keys, $this->require_integer_keys);
     }
 }
 /**
  * Process the values
  */
 public function Values($values)
 {
     if (!empty($values)) {
         parent::Values($values);
         $values = array();
         // find min, max, strip out nulls
         $min = $max = NULL;
         foreach ($this->values[0] as $item) {
             if (!is_null($item->value)) {
                 if (is_null($min) || $item->value < $min) {
                     $min = $item->value;
                 }
                 if (is_null($max) || $item->value > $max) {
                     $max = $item->value;
                 }
                 $values[] = $item->value;
             }
         }
         // calculate increment?
         if ($this->increment <= 0) {
             $diff = $max - $min;
             if ($diff <= 0) {
                 $inc = 1;
             } else {
                 $inc = pow(10, floor(log10($diff)));
                 $d1 = $diff / $inc;
                 if (($inc != 1 || !is_integer($diff)) && $d1 < 4) {
                     if ($d1 < 3) {
                         $inc *= 0.2;
                     } else {
                         $inc *= 0.5;
                     }
                 }
             }
             $this->increment = $inc;
         }
         // prefill the map with nulls
         $map = array();
         $start = $this->Interval($min);
         $end = $this->Interval($max, true) + $this->increment / 2;
         Graph::SetNumStringOptions($this->settings['decimal'], $this->settings['thousands']);
         for ($i = $start; $i < $end; $i += $this->increment) {
             $key = (int) $i;
             $map[$key] = null;
         }
         foreach ($values as $val) {
             $k = (int) $this->Interval($val);
             if (!array_key_exists($k, $map)) {
                 $map[$k] = 1;
             } else {
                 $map[$k]++;
             }
         }
         if ($this->percentage) {
             $total = count($values);
             $pmap = array();
             foreach ($map as $k => $v) {
                 $pmap[$k] = 100 * $v / $total;
             }
             $values = $pmap;
         } else {
             $values = $map;
         }
         // turn off structured data
         $this->structure = NULL;
         $this->structured_data = FALSE;
         // set up options to make bar graph class draw the histogram properly
         $this->minimum_units_y = 1;
         $this->subdivision_h = $this->increment;
         // no subdiv below bar size
         $this->grid_division_h = max($this->increment, $this->grid_division_h);
         $amh = $this->axis_min_h;
         if (empty($amh)) {
             $this->axis_min_h = $start;
         }
     }
     parent::Values($values);
 }
示例#3
0
 /**
  * construct multigraph
  */
 public function Values($values)
 {
     parent::Values($values);
     $this->multi_graph = new MultiGraph($this->values, $this->force_assoc);
 }