【问题标题】:How to fill the space between the grid lines with multiple colours in JpGraph?如何在 JpGraph 中用多种颜色填充网格线之间的空间?
【发布时间】:2018-12-28 12:37:41
【问题描述】:

因此,使用 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);
}

我怀疑需要更新更多脚本以适应这种变化?

【问题讨论】:

    标签: php colors linegraph jpgraph


    【解决方案1】:

    此解决方案允许您保留交替选项,但是当您传入更多颜色(在我的情况下为 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);
                    }
                }
    

    【讨论】:

      猜你喜欢
      • 2020-10-17
      • 1970-01-01
      • 1970-01-01
      • 2011-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-16
      • 1970-01-01
      相关资源
      最近更新 更多