Question

I'm using the latest version of JPGraph and I'm trying to alter the graph_api file to show values on Group Bar Plots. Here's a snippet of code to show my alterations (for those looking at the API, this is in the graph_group function):

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

According to the API, using "value->show()" should display the values. When I add in that last line (for $gbplot), the graph doesn't show. If I comment it out, the graph will display sans values. What am I missing?

Was it helpful?

Solution

Apparently the issue has to deal with the fact that JPGraph won't let you overwrite its theme by default. I found by setting the theme to null allowed me to make more extensive changes. IMO, that's a pretty dumb setup, but c'est la vie. Here's what my graph definition looks like now:

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

The 'graph_theme' line is the new addition made that fixed the issue for me. I hope this helps others in the future as it's not explicitly stated in their API.

OTHER TIPS

the reason is here : // methods to change designs of each plot should be used after $graph->add($plot) method. // This is really counter-intuitive. But it works !!

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top