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