Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

display items' values in bar chart in Jpgraph

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!

like image 270
Reza Saberi Avatar asked Dec 16 '22 07:12

Reza Saberi


2 Answers

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.

like image 127
Oscar Pérez Avatar answered Jan 05 '23 23:01

Oscar Pérez


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

$graph->Add($plot);
$plot->value->Show();
like image 31
EnergyMud Avatar answered Jan 06 '23 00:01

EnergyMud