因此,使用SetFill函数在网格线之间交替两种颜色非常简单,但是,我的线图中需要7种不同的颜色。
$graph->ygrid->SetFill(true,'red','blue', [5 more colours etc] );
此刻,我尝试将更多参数添加到jpgrapgh.php中的SetFill函数中,但没有成功。请参见下面的代码示例:
function SetFill($aFlg=true,$aColor1='lightgray',$aColor2='lightblue',$aColor3='darkblue') {
$this->fill = $aFlg;
$this->fillcolor = array( $aColor1, $aColor2, $aColor3);
}
我怀疑需要更新更多脚本以适应此更改?
答案 0 :(得分:0)
此解决方案允许您保留交替选项,但是当您传递更多颜色(在我的情况下为7)时,它将使用传入的颜色填充网格线之间的空间。
$graph->ygrid->SetFill(true,'red','orange','orange','green','orange','orange','red');
将SetFill函数更新为:
function SetFill($aFlg=true,$aColor1='lightgray',$aColor2='lightblue',$aColor3=null,$aColor4=null,$aColor5=null,$aColor6=null,$aColor7=null) {
$this->fill = $aFlg;
$this->fillcolor = array( $aColor1, $aColor2, $aColor3, $aColor4, $aColor5, $aColor6, $aColor7 );
$this->fillcolor = array_filter($this->fillcolor);
}
在DoStroke函数更新中:
// If we have passed in 7 colours
if(count($this->fillcolor)==7) {
// Loop out all 7 the colours
while ($i < $nbrgrids) {
$this->img->SetColor($this->fillcolor[$i - 1]); // Offset by 1 because array keys start at 0
$y1 = $y2;
$y2 = $aTicksPos[$i++];
$this->img->FilledRectangle($xl, $y1, $xr, $y2);
}
} else {
// Otherwise, do the normal alternation loop
while ($i < $nbrgrids) {
$y1 = $y2;
$y2 = $aTicksPos[$i++];
$this->img->SetColor($this->fillcolor[$i & 1]);
$this->img->FilledRectangle($xl, $y1, $xr, $y2);
}
}