1 | <?php // content="text/plain; charset=utf-8" |
---|
2 | require_once ('jpgraph/jpgraph.php'); |
---|
3 | require_once ('jpgraph/jpgraph_scatter.php'); |
---|
4 | |
---|
5 | DEFINE('WORLDMAP','worldmap1.jpg'); |
---|
6 | |
---|
7 | function markCallback($y,$x) { |
---|
8 | // Return array width |
---|
9 | // width,color,fill color, marker filename, imgscale |
---|
10 | // any value can be false, in that case the default value will |
---|
11 | // be used. |
---|
12 | // We only make one pushpin another color |
---|
13 | if( $x == 54 ) |
---|
14 | return array(false,false,false,'red',0.8); |
---|
15 | else |
---|
16 | return array(false,false,false,'green',0.8); |
---|
17 | } |
---|
18 | |
---|
19 | // Data arrays |
---|
20 | $datax = array(10,20,30,40,54,60,70,80); |
---|
21 | $datay = array(12,23,65,18,84,28,86,44); |
---|
22 | |
---|
23 | // Setup the graph |
---|
24 | $graph = new Graph(400,270); |
---|
25 | |
---|
26 | // We add a small 1pixel left,right,bottom margin so the plot area |
---|
27 | // doesn't cover the frame around the graph. |
---|
28 | $graph->img->SetMargin(1,1,1,1); |
---|
29 | $graph->SetScale('linlin',0,100,0,100); |
---|
30 | |
---|
31 | // We don't want any axis to be shown |
---|
32 | $graph->xaxis->Hide(); |
---|
33 | $graph->yaxis->Hide(); |
---|
34 | |
---|
35 | // Use a worldmap as the background and let it fill the plot area |
---|
36 | $graph->SetBackgroundImage(WORLDMAP,BGIMG_FILLPLOT); |
---|
37 | |
---|
38 | // Setup a nice title with a striped bevel background |
---|
39 | $graph->title->Set("Pushpin graph"); |
---|
40 | $graph->title->SetFont(FF_ARIAL,FS_BOLD,16); |
---|
41 | $graph->title->SetColor('white'); |
---|
42 | $graph->SetTitleBackground('darkgreen',TITLEBKG_STYLE1,TITLEBKG_FRAME_BEVEL); |
---|
43 | $graph->SetTitleBackgroundFillStyle(TITLEBKG_FILLSTYLE_HSTRIPED,'blue','darkgreen'); |
---|
44 | |
---|
45 | // Finally create the scatterplot |
---|
46 | $sp = new ScatterPlot($datay,$datax); |
---|
47 | |
---|
48 | // We want the markers to be an image |
---|
49 | $sp->mark->SetType(MARK_IMG_PUSHPIN,'blue',0.6); |
---|
50 | |
---|
51 | // Install the Y-X callback for the markers |
---|
52 | $sp->mark->SetCallbackYX('markCallback'); |
---|
53 | |
---|
54 | // ... and add it to the graph |
---|
55 | $graph->Add($sp); |
---|
56 | |
---|
57 | // .. and output to browser |
---|
58 | $graph->Stroke(); |
---|
59 | |
---|
60 | ?> |
---|
61 | |
---|
62 | |
---|