Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 错误的图例颜色_Php_Jpgraph - Fatal编程技术网

Php 错误的图例颜色

Php 错误的图例颜色,php,jpgraph,Php,Jpgraph,我正在将一个非常旧的代码库从JpGraph/2.3升级到4.2.0。最大的问题是图例颜色不再与图形颜色匹配: $good = new BarPlot([10, 12, 11, 9]); $good->SetLegend('Good'); $good->SetFillGradient('#089B81', '#089B81:1.2', GRAD_LEFT_REFLECTION); $bad = new BarPlot([4, 5, 2, 8]); $bad->SetLegend

我正在将一个非常旧的代码库从JpGraph/2.3升级到4.2.0。最大的问题是图例颜色不再与图形颜色匹配:

$good = new BarPlot([10, 12, 11, 9]);
$good->SetLegend('Good');
$good->SetFillGradient('#089B81', '#089B81:1.2', GRAD_LEFT_REFLECTION);

$bad = new BarPlot([4, 5, 2, 8]);
$bad->SetLegend('Bad');
$bad->SetFillGradient('#9B0829', '#9B0829:1.2', GRAD_LEFT_REFLECTION);

$both = new AccBarPlot([$good, $bad]);

$graph = new Graph(400, 300, 'auto');
$graph->SetScale('textlin');
$graph->Add($both);
$graph->Stroke();

显然,图例颜色现在是在主题中硬编码的(PHP类扩展了
主题
抽象类)


有没有办法手动设置图例颜色,或者像第2版那样自动设置图例颜色?我有几个情节使用了不同的颜色,为每个颜色组合写主题看起来太过分了。

最后我写了一个主题:

class MyJpGraphTheme extends UniversalTheme
{
    function GetColorList()
    {
        $colors = array();
        if (isset($this->graph->plots)) {
            foreach ($this->graph->plots as $level1) {
                if (!isset($level1->plots)) {
                    continue;
                }
                foreach ($level1->plots as $level2) {
                    $colors[] = $level2->color;
                }
            }
        }
        return $colors ? $colors : parent::GetColorList();
    }
}
请不要在家里这样做。它对我来说很有用,因为
color
属性实际上被填充到了我真正的代码库中,我认为在我共享的简化测试用例中不会发生这种情况这只是一个丑陋的黑客行为。