Blame view

site/jpgraph/Examples/barformatcallbackex1.php 742 Bytes
8ec98c9f   Guillaume   MAJ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  <?php // content="text/plain; charset=utf-8"
  require_once ('jpgraph/jpgraph.php');
  require_once ('jpgraph/jpgraph_bar.php');
  
  $data = array(0.1235,0.4567,0.67,0.45,0.832);
  
  // Callback function
  // Get called with the actual value and should return the
  // value to be displayed as a string
  function cbFmtPercentage($aVal) {
      return sprintf("%.1f%%",100*$aVal); // Convert to string
  }
  
  // Create the graph. 
  $graph = new Graph(400,300);	
  $graph->SetScale("textlin");
  
  // Create a bar plots
  $bar1 = new BarPlot($data);
  
  // Setup the callback function
  $bar1->value->SetFormatCallback("cbFmtPercentage");
  $bar1->value->Show();
  
  // Add the plot to the graph
  $graph->Add($bar1);
  
  // .. and send the graph back to the browser
  $graph->Stroke();
  ?>