| 1 |
lars |
1 |
<?php
|
|
|
2 |
//
|
|
|
3 |
// Example of CSIM frequence bar that uses the cache
|
|
|
4 |
//
|
|
|
5 |
include_once ("../jpgraph.php");
|
|
|
6 |
include_once ("../jpgraph_bar.php");
|
|
|
7 |
include_once ("../jpgraph_line.php");
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
// Utility function to calculate the accumulated frequence
|
|
|
11 |
// for a set of values and ocurrences
|
|
|
12 |
function accfreq($data) {
|
|
|
13 |
rsort($data);
|
|
|
14 |
$s = array_sum($data);
|
|
|
15 |
$as = array($data[0]);
|
|
|
16 |
$asp = array(100*$as[0]/$s);
|
|
|
17 |
$n = count($data);
|
|
|
18 |
for( $i=1; $i < $n; ++$i ) {
|
|
|
19 |
$as[$i] = $as[$i-1]+$data[$i];
|
|
|
20 |
$asp[$i] = 100.0*$as[$i]/$s;
|
|
|
21 |
}
|
|
|
22 |
return $asp;
|
|
|
23 |
}
|
|
|
24 |
|
|
|
25 |
// some data
|
|
|
26 |
$data_freq = array(22,20,12,10,5,4,2);
|
|
|
27 |
$data_accfreq = accfreq($data_freq);
|
|
|
28 |
|
|
|
29 |
// Create the graph.
|
|
|
30 |
$graph = new Graph(350,250);
|
|
|
31 |
|
|
|
32 |
// We need to make this extra call for CSIM scripts
|
|
|
33 |
// that make use of the cache. If the cache contains this
|
|
|
34 |
// graph the HTML wrapper will be returned and then the
|
|
|
35 |
// method will call exit() and hence NO LINES AFTER THIS
|
|
|
36 |
// CALL WILL BE EXECUTED.
|
|
|
37 |
// $graph->CheckCSIMCache('auto');
|
|
|
38 |
|
|
|
39 |
// Setup some basic graph parameters
|
|
|
40 |
$graph->SetScale("textlin");
|
|
|
41 |
$graph->SetY2Scale('lin',0,100);
|
|
|
42 |
$graph->img->SetMargin(50,70,30,40);
|
|
|
43 |
$graph->yaxis->SetTitleMargin(30);
|
|
|
44 |
$graph->SetMarginColor('#EEEEEE');
|
|
|
45 |
|
|
|
46 |
// Setup titles and fonts
|
|
|
47 |
$graph->title->Set("Frequence plot");
|
|
|
48 |
$graph->xaxis->title->Set("X-title");
|
|
|
49 |
$graph->yaxis->title->Set("Y-title");
|
|
|
50 |
|
|
|
51 |
$graph->title->SetFont(FF_FONT1,FS_BOLD);
|
|
|
52 |
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
|
|
|
53 |
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
|
|
|
54 |
|
|
|
55 |
// Turn the tickmarks
|
|
|
56 |
$graph->xaxis->SetTickSide(SIDE_DOWN);
|
|
|
57 |
$graph->yaxis->SetTickSide(SIDE_LEFT);
|
|
|
58 |
|
|
|
59 |
$graph->y2axis->SetTickSide(SIDE_RIGHT);
|
|
|
60 |
$graph->y2axis->SetColor('black','blue');
|
|
|
61 |
$graph->y2axis->SetLabelFormat('%3d.0%%');
|
|
|
62 |
|
|
|
63 |
// Create a bar pot
|
|
|
64 |
$bplot = new BarPlot($data_freq);
|
|
|
65 |
|
|
|
66 |
// Create targets and alt texts for the image maps. One for each bar
|
|
|
67 |
// (In this example this is just "dummy" targets)
|
|
|
68 |
$targ=array("#1","#2","#3","#4","#5","#6","#7");
|
|
|
69 |
$alts=array("val=%d","val=%d","val=%d","val=%d","val=%d","val=%d","val=%d");
|
|
|
70 |
$bplot->SetCSIMTargets($targ,$alts);
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
// Create accumulative graph
|
|
|
74 |
$lplot = new LinePlot($data_accfreq);
|
|
|
75 |
|
|
|
76 |
// We want the line plot data point in the middle of the bars
|
|
|
77 |
$lplot->SetBarCenter();
|
|
|
78 |
|
|
|
79 |
// Use transperancy
|
|
|
80 |
$lplot->SetFillColor('lightblue@0.6');
|
|
|
81 |
$lplot->SetColor('blue@0.6');
|
|
|
82 |
//$lplot->SetColor('blue');
|
|
|
83 |
$graph->AddY2($lplot);
|
|
|
84 |
|
|
|
85 |
|
|
|
86 |
// Setup the bars
|
|
|
87 |
$bplot->SetFillColor("orange@0.2");
|
|
|
88 |
$bplot->SetValuePos('center');
|
|
|
89 |
$bplot->value->SetFormat("%d");
|
|
|
90 |
$bplot->value->SetFont(FF_ARIAL,FS_NORMAL,9);
|
|
|
91 |
$bplot->value->Show();
|
|
|
92 |
|
|
|
93 |
// Add it to the graph
|
|
|
94 |
$graph->Add($bplot);
|
|
|
95 |
|
|
|
96 |
// Send back the HTML page which will call this script again
|
|
|
97 |
// to retrieve the image.
|
|
|
98 |
$graph->StrokeCSIM('barlinefreq_csimex1.php');
|
|
|
99 |
|
|
|
100 |
?>
|