JPGraph-条形图不显示值


JPGraph - Bar Graphs are not showing values

我使用的是最新版本的JPGraph,我正在尝试更改graph_api文件以在Group Bar Plots上显示值。下面是一段代码来显示我的更改(对于那些关注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)时,图形不会显示。如果我把它注释掉,图形将显示sans值。我错过了什么?

显然,问题在于JPGraph默认情况下不允许覆盖其主题。我发现通过将主题设置为null,我可以进行更广泛的更改。IMO,这是一个非常愚蠢的设置,但这是生活。下面是我的图形定义:

$graph = new Graph( $p_graph_width, $p_graph_height );
$graph->SetScale('textlin');
$graph->graph_theme = null;
$graph->SetFrame(false);

"graph_theme"行是为我修复了这个问题的新添加。我希望这对将来的其他人有帮助,因为他们的API中没有明确说明。

原因如下://更改每个绘图设计的方法应在$graph->add($plot)方法之后使用。//这确实是违背直觉的。但它有效!!

$graph->Add($bplot);
$bplot->value->show();

//感谢:http://webdeveloperoddities.blogspot.com/2010/10/jpgraph-cannot-change-line-colour-or.html