错误的传奇色彩

时间:2018-03-13 09:34:46

标签: php jpgraph

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

Plot with wrong colours

$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();

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

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

1 个答案:

答案 0 :(得分:0)

最后我写了一个主题:

string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Images");
foreach (string file in Directory.GetFiles(path, "*.bmp"))
{
    // there is file name
}

请不要在家里这样做。它适用于我,因为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(); } } 属性实际填充在我的真实代码库中,我认为这不会发生在我共享的简化测试用例中。 这只是一个丑陋的黑客。

相关问题