display items' values in bar chart in Jpgraph

6.6k Views Asked by At

I am using jpgraph bar chart. It all works fine but there is one thing I could not really figure it out. I need to display the value of each bar on the top of that bar (column) but it seems like I am missing something that I cant do it.

I have tried using the following:

$bplot->value->Show();

But yet it does not work! Any help is GREATLY appreciated!

4

There are 4 best solutions below

0
On

This example shows it can be done, and it gives a complete example of how to pull it off:

http://enacit1.epfl.ch/php/jpgraph/docs/html/exframes/frame_example20.1.html

I'd be glad to look at your code and troubleshoot if you require help beyond this.

0
On

Putting the value on top of the bar:

$bplot->SetValuePos('top');

Changing the angle:

$bplot->value->SetAngle(90);

Hiding value that are 0:

$bplot->value->HideZero();
0
On

Call the Show() method after you've added the plot to the graph.

$graph->Add($plot);
$plot->value->Show();
0
On

It is an old question, but as I had the same problem and I solved it, I'm posting this answer as a future reference.

My problem was the order of the invoked methods. You MUST call Show after addnig the plot to the graph. As an example:

$graph = new \Graph($width, $height);

[... init graph ...]

$plot = new \BarPlot($datay);
$graph->Add($plot);
$plot->value->Show();
$plot->value->SetColor("black","darkred"); 
$plot->value->SetFormat('%01.2f');  

I hope it helps someone.