Kleur laten wisselen

Status
Niet open voor verdere reacties.

Ewergreen

Gebruiker
Lid geworden
15 mrt 2008
Berichten
273
PHP:
         if ($this->variousColors) $color = ($i % 2) + 1;
         else $color = 1;
         $i++;

Dit stukje script wisselt de kleur (afbeelding) van mijn grafiek steeds af. Nu wil ik echter dat de eerste keer kleur 1 gebruikt wordt, dan 6 keer kleur 2 en dan terug kleur 1 voor de laatste. Iemand tips?

Volledige script dat ik include:

PHP:
<?php
class maxChart {
   var $data;         // The data array to display
   var $type = 0;     // Vertical:1 or Horizontal:0 chart
   var $title;        // The title of the chart
   var $width = 300;  // The chart box width 
   var $height = 200; // The chart box height
   var $metaSpaceHorizontal = 60; // Total space needed for chart title + bar title + bar value
   var $metaSpaceVertical = 60; // Total space needed for chart title + bar title + bar value
   var $variousColors = true;
   
   function maxChart($data){
      $this->data = $data;
   }
   
   function displayChart($title='', $type, $width=700, $height=200, $variousColor=true){
      $this->type   = $type;
      $this->title  = $title;
      $this->width  = $width;
      $this->height = $height;
      $this->variousColors = $variousColor;

      echo '<div class="chartbox" style="width:'.$this->width.'px; height:'.$this->height.'px;">
                <h2>'.$this->title.'</h2>'."\r\n";

        
      if ($this->type == 1)  $this->drawVertical();
      else $this->drawHorizontal();   
    
      echo '    </div>';

   }
   
   function getMaxDataValue(){
      $max = 0;
      
      foreach ($this->data as $key=>$value) {
         if ($value > $max) $max = $value;	
      }
      
      return $max;
   }
   
   function getElementNumber(){
      return sizeof($this->data);
   }
   
   function drawVertical(){
      $multi = ($this->height -$this->metaSpaceHorizontal) / $this->getMaxDataValue();
      $max   = $multi * $this->getMaxDataValue();
      $barw  = floor($this->width / $this->getElementNumber()) - 5;
      
      $i = 1;
      
      foreach ($this->data as $key=>$value) {
         $b = floor($max - ($value*$multi));
         $a = $max - $b;
         
         if ($this->variousColors) $color = ($i % 2) + 1;
         else $color = 1;
         $i++;
         
         echo '  <div class="barv">'."\r\n";
         echo '    <div class="barvvalue" style="margin-top:'.$b.'px; width:'.$barw.'px;">'.$value.'</div>'."\r\n";
	     echo '    <div><img src="style/images/bar'.$color.'.png" style="width:'.$barw.'px; height:'.$a.'px;" /></div>'."\r\n";
         echo '    <div class="barvvalue" style="width:'.$barw.'px;">'.$key.'</div>'."\r\n";
         echo '  </div>'."\r\n";

      }
      
   }
   
   function drawHorizontal(){
      $multi = ($this->width-170) / $this->getMaxDataValue();
      $max   = $multi * $this->getMaxDataValue();
      $barh  = floor(($this->height - 35) / $this->getElementNumber());
      
      $i = 1;
      
      foreach ($this->data as $key=>$value) {
         $b = floor($value*$multi);

         if ($this->variousColors) $color = ($i % 5) + 1;
         else $color = 1;
         $i++;
         
         echo '  <div class="barh" style="height:'.$barh.'px;">'."\r\n";
         echo '    <div class="barhcaption" style="line-height:'.$barh.'px; width:90px;">'.$key.'</div>'."\r\n";
         echo '    <div class="barhimage"><img src="style/images/barh'.$color.'.png" style="width:'.$b.'px; height:'.$barh.'px;" /></div>'."\r\n";
         echo '    <div class="barhvalue" style="line-height:'.$barh.'px; width:30px;">'.$value.'</div>'."\r\n";
         echo '  </div>';

      }
      
   }
   
   
}


?>
 
Zoiets?

PHP:
if ($this->variousColors)
  if ( $i % 7 == 0 ) {
    $color = 1;
  }  
  else {
    $color = 2;
  }

  $i++;
}
else {
         else $color = 1;
}
 
Ik heb valsgespeeld. Ik heb gewoon "7" genomen voor de afbeeldingen, dan zeven afbeeldingen gemaakt en ze telkens mijn gewenste kleur gegeven.
 
Haha, kan ook :)

Als het een eenmalig scriptje is moet je ook niet te moeilijk doen :)

Vergeet alleen niet om een goede oplossing te zoeken als je hier nog vaker tegenaan loopt.
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan