<?php
require_once ("jpgraph/jpgraph.php");
require_once ("jpgraph/jpgraph_scatter.php");
$data = array(
array(1,12,10,'orange'),
array(3,41,15,'red'),
array(4,5,19,'lightblue'),
array(5,70,22,'yellow')
);
$n = count($data);
for( $i=0; $i < $n; ++$i ) {
$datax[$i] = $data[$i][0];
$datay[$i] = $data[$i][1];
$format[strval($datax[$i])][strval($datay[$i])] = array($data[$i][2],$data[$i][3]);
}
function FCallback($aYVal,$aXVal) {
global $format;
return array($format[strval($aXVal)][strval($aYVal)][0],'',
$format[strval($aXVal)][strval($aYVal)][1],'','');
}
$graph = new Graph(450,300,'auto');
$graph->SetScale("intlin");
$graph->SetMargin(40,40,40,40);
$graph->SetMarginColor('wheat');
$graph->title->Set("Example of ballon scatter plot with X,Y callback");
$graph->title->SetFont(FF_ARIAL,FS_BOLD,12);
$graph->title->SetMargin(10);
$graph->yaxis->scale->SetGrace(50,10);
$graph->xaxis->scale->SetGrace(50,10);
$graph->xaxis->SetPos('min');
$graph->xscale->SetAutoMin(0);
$sp1 = new ScatterPlot($datay,$datax);
$sp1->mark->SetType(MARK_FILLEDCIRCLE);
$sp1->value->Show();
$sp1->value->SetFont(FF_FONT1,FS_BOLD);
$sp1->mark->SetCallbackYX("FCallback");
$graph->Add($sp1);
$graph->Stroke();
?> |