我正在使用最新版本的 JPGraph,并且尝试更改 graph_api 文件以在组条形图上显示值。下面是一段代码,用于显示我的更改(对于那些查看 API 的人来说,这是在 graph_group 函数中):
$tot = new BarPlot( array_values( $total ) );
$tot->value->show();
$tot->value->SetFormat('%2d');
$tot->value->SetColor('black','black');
$tot->value->SetFont($t_graph_font,FS_BOLD,9);
$tot->SetFillColor('lightblue');
$tot->SetWidth(0.7);
$tot->SetLegend( lang_get( 'legend_total' ) );
$graph->Add($tot);
$p1 = new BarPlot( array_values( $p_metrics['open'] ) );
$p1->SetFillColor( 'yellow' );
$p1->SetWidth( 1 );
$p1->SetLegend( plugin_lang_get( 'legend_opened' ) );
$p1->value->show();
$p1->value->SetColor('white','white');
$p1->value->SetFormat('%2d');
$p1->value->SetFont($t_graph_font,FS_BOLD,8);
$p1->SetFillColor('red');
$p1->SetLegend( lang_get( 'legend_still_open' ) );
$p2 = new BarPlot( array_values( $p_metrics['closed'] ) );
$p2->SetFillColor( 'blue' );
$p2->SetWidth( 1 );
$p2->SetLegend( plugin_lang_get( 'legend_closed' ) );
$p2->value->show();
$p2->value->SetFormat('%2d');
$p2->value->SetColor('black','black');
$p2->SetFillColor('forestgreen');
$p2->SetWidth(0.5);
$p2->SetLegend( lang_get( 'legend_closed' ) );
$gbplot = new GroupBarPlot( array( $p1, $p2 ) );
$gbplot->value->show();
$graph->Add( $gbplot );
根据 API,使用“value->show()”应该显示值。当我添加最后一行(对于 $gbplot)时,图表不显示。如果我将其注释掉,图表将显示无值。我缺少什么?
显然,这个问题必须解决 JPGraph 默认情况下不允许您覆盖其主题的事实。我发现通过将主题设置为 null 可以让我进行更广泛的更改。在我看来,这是一个相当愚蠢的设置,但这就是生活。这是我的图形定义现在的样子:
$graph = new Graph( $p_graph_width, $p_graph_height );
$graph->SetScale('textlin');
$graph->graph_theme = null;
$graph->SetFrame(false);
“graph_theme”行是新添加的内容,为我解决了这个问题。我希望这对将来的其他人有所帮助,因为他们的 API 中没有明确说明这一点。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)