Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
include ("../jpgraph.php");
3
include ("../jpgraph_scatter.php");
4
 
5
// Each ballon is specificed by four values.
6
// (X,Y,Size,Color)
7
$data = array(
8
    array(1,12,10,'orange'),
9
    array(3,41,15,'red'),
10
    array(4,5,19,'lightblue'),
11
    array(5,70,22,'yellow')
12
);
13
 
14
// We need to create X,Y data vectors suitable for the
15
// library from the above raw data.
16
$n = count($data);
17
for( $i=0; $i < $n; ++$i ) {
18
 
19
    $datax[$i] = $data[$i][0];
20
    $datay[$i] = $data[$i][1];
21
 
22
    // Create a faster lookup array so we don't have to search
23
    // for the correct values in the callback function
24
    $format[strval($datax[$i])][strval($datay[$i])] = array($data[$i][2],$data[$i][3]);
25
 
26
}
27
 
28
// Callback for markers
29
// Must return array(width,border_color,fill_color,filename,imgscale)
30
// If any of the returned values are '' then the
31
// default value for that parameter will be used (possible empty)
32
function FCallback($aYVal,$aXVal) {
33
    global $format;
34
    return array($format[strval($aXVal)][strval($aYVal)][0],'',
35
		 $format[strval($aXVal)][strval($aYVal)][1],'','');
36
}
37
 
38
// Setup a basic graph
39
$graph = new Graph(450,300,'auto');
40
$graph->SetScale("intlin");
41
$graph->SetMargin(40,40,40,40);
42
$graph->SetMarginColor('wheat');
43
 
44
$graph->title->Set("Example of ballon scatter plot with X,Y callback");
45
$graph->title->SetFont(FF_ARIAL,FS_BOLD,12);
46
$graph->title->SetMargin(10);
47
 
48
// Use a lot of grace to get large scales since the ballon have
49
// size and we don't want them to collide with the X-axis
50
$graph->yaxis->scale->SetGrace(50,10);
51
$graph->xaxis->scale->SetGrace(50,10);
52
 
53
// Make sure X-axis as at the bottom of the graph and not at the default Y=0
54
$graph->xaxis->SetPos('min');
55
 
56
// Set X-scale to start at 0
57
$graph->xscale->SetAutoMin(0);
58
 
59
// Create the scatter plot
60
$sp1 = new ScatterPlot($datay,$datax);
61
$sp1->mark->SetType(MARK_FILLEDCIRCLE);
62
 
63
// Uncomment the following two lines to display the values
64
$sp1->value->Show();
65
$sp1->value->SetFont(FF_FONT1,FS_BOLD);
66
 
67
// Specify the callback
68
$sp1->mark->SetCallbackYX("FCallback");
69
 
70
// Add the scatter plot to the graph
71
$graph->Add($sp1);
72
 
73
// ... and send to browser
74
$graph->Stroke();
75
 
76
?>
77
 
78