<?php
include ("jpgraph/jpgraph.php");
include ("jpgraph/jpgraph_bar.php");
include_once ("jpgraph/jpgraph_pie.php");
include_once ("jpgraph/jpgraph_pie3d.php");
//$title 图片标题
//$dataArray array(数据1,数据2,………)
//$dataName array(名称1,名称2,………)
//$urlArray array(URL1,URL2,………)
function BarGraphSummary($title ,$dadaArray , $dataName , $urlArray)
{
// Create the graph.
// One minute timeout for the cached image
// INLINE_NO means don't stream it back to the browser.
$n = count($dadaArray);
$sizeX = $n*40+60;
if($sizeX<400) //确保图片大小能把图片显示下
$sizeX = 400;
$graph = new Graph($sizeX,300,'auto');
$graph->SetScale("textlin");
$graph->img->SetMargin(60,30,20,60);
$graph->yaxis->SetTitleMargin(45);
$graph->yaxis->scale->SetGrace(30);
$graph->SetShadow();
// Turn the tickmarks
$graph->xaxis->SetTickSide(SIDE_DOWN);
$graph->yaxis->SetTickSide(SIDE_LEFT);
// Create a bar pot
$bplot = new BarPlot($dadaArray);
// Create targets for the image maps. One for each column
$targ=array("bar_clsmex1.php#1","bar_clsmex1.php#2","bar_clsmex1.php#3","bar_clsmex1.php#4","bar_clsmex1.php#5","bar_clsmex1.php#6");
$alts=array("val=%d","val=%d","val=%d","val=%d","val=%d","val=%d");
$bplot->SetCSIMTargets($urlArray,$dataName);
$bplot->SetFillColor("orange");
// Use a shadow on the bar graphs (just use the default settings)
$bplot->SetShadow();
$bplot->value->SetFormat("%d");
$bplot->value->SetFont(FF_ARIAL,FS_NORMAL,9);
$bplot->value->SetColor("blue");
$bplot->value->Show();
$graph->Add($bplot);
$graph->title->Set($title);
$graph->xaxis->title->Set("X轴");
$graph->xaxis->SetTickLabels($dataName); //设置x轴标签
$graph->xaxis->SetLabelAngle(-90); //设置标签角度
$graph->xaxis->SetFont(FF_SIMSUN);
$graph->yaxis->title->Set("Y轴(单位:人)");
$graph->title->SetFont(FF_SIMSUN,FS_BOLD);
$graph->yaxis->title->SetFont(FF_SIMSUN,FS_BOLD);
$graph->xaxis->title->SetFont(FF_SIMSUN,FS_BOLD);
// Send back the HTML page which will call this script again
// to retrieve the image.
$graph->StrokeCSIM();
}
function Pie3DGraphSummary($title ,$dadaArray , $dataName , $urlArray)
{
// Create the Pie Graph.
$graph = new PieGraph(550,300,'auto');
$graph->SetShadow();
// Set A title for the plot
$graph->title->Set($title);
$graph->title->SetFont(FF_SIMSUN,FS_BOLD);
$graph->legend->SetFont(FF_SIMSUN,FS_BOLD); //设置标签字体
//$graph->legend->SetCenter(0.4,0.5);
$p1 = new PiePlot3D($dadaArray);
//数据处理
$i = 0;
foreach ($dataName as $key=>$tempName)
{
$dataName[$key] .='('.$dadaArray[$i].'人)';
$i++;
}
$p1->SetLegends($dataName);
$p1->SetLabelType(0); //设置标签类型,即显示百分比还是人数
//$graph->legend->SetFillColor('white');
$p1->SetCSIMTargets($urlArray,$dataName); //设置热点
// Use absolute labels
//$p1->SetLabelType(1);
//$p1->value->SetFormat("%d");
// Move the pie slightly to the left
$p1->SetCenter(0.35,0.5); //设置饼图位置
// Setup the labels
$p1->SetLabelType(PIE_VALUE_PER);
$p1->value->Show();
$p1->value->SetFont(FF_ARIAL,FS_NORMAL,9);
$p1->value->SetFormat('%2.1f%%');
$graph->Add($p1);
// Send back the HTML page which will call this script again
// to retrieve the image.
$graph->StrokeCSIM();
}
function Pie2DGraphSummary($title ,$dadaArray , $dataName , $urlArray)
{
// Create the Pie Graph.
$graph = new PieGraph(550,300);
// Set A title for the plot
$graph->title->Set($title);
$graph->title->SetFont(FF_SIMSUN,FS_BOLD,12);
$graph->title->SetColor("darkblue");
$graph->legend->Pos(0.1,0.2);
$graph->legend->SetFont(FF_SIMSUN,FS_BOLD);
// Create pie plot
$p1 = new PiePlot($dadaArray);
//数据处理
$i = 0;
foreach ($dataName as $key=>$tempName)
{
$dataName[$key] .='('.$dadaArray[$i].'人)';
$i++;
}
$p1->SetLegends($dataName);
$p1->SetCenter(0.35,0.5); //设置饼图位置
$p1->SetSize(0.3);
$p1->SetLabelType(0);
$p1->SetCenter(0.35,0.5);
$p1->SetCSIMTargets($urlArray,$dataName);
// Setup the labels
$p1->SetLabelType(PIE_VALUE_PER);
$p1->value->Show();
$p1->value->SetFont(FF_ARIAL,FS_NORMAL,9);
$p1->value->SetFormat('%2.1f%%');
// Add and stroke
$graph->Add($p1);
$graph->StrokeCSIM();
}
/*$title = "测试";
$data = array(22,10,10,10,10,10,10,10);
$name = array("海口","文昌","琼海","三亚","乐东","屯昌","琼海","博鳌");
$url = array("xx.php","xx.php","yy.php","zzz.php","xx.php","xx.php","yy.php","yy.php");
Pie3DGraphSummary($title,$data,$name,$url);*/
?>