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>';
}
}
}
?>