pChart图表插件使用

时间:2023-12-22 11:47:20
<?php
/* 柱形图 */ #引入库文件
include("../class/pData.class.php");
include("../class/pDraw.class.php");
include("../class/pImage.class.php"); #创建数据对象
$MyData = new pData();
$MyData->addPoints(array(150,220,300,-250,-420,-200,300,200,100),"Server A");
$MyData->addPoints(array(140,0,340,-300,-320,-300,200,100,50),"Server B");
$MyData->setAxisName(0,"Hits");
$MyData->addPoints(array("January","February","March","April","May","Juin","July","August","September"),"Months");
$MyData->setSerieDescription("Months","Month");
$MyData->setAbscissa("Months"); #创建图形对象
$myPicture = new pImage(700,230,$MyData); #关闭平滑模式
$myPicture->Antialias = FALSE; #增加边框
$myPicture->drawGradientArea(0,0,700,230,DIRECTION_VERTICAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>100));
$myPicture->drawGradientArea(0,0,700,230,DIRECTION_HORIZONTAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>20));
$myPicture->drawRectangle(0,0,699,229,array("R"=>0,"G"=>0,"B"=>0)); #设置默认字体
$myPicture->setFontProperties(array("FontName"=>"../fonts/pf_arma_five.ttf","FontSize"=>6)); #定义图像区域
$myPicture->setGraphArea(60,40,650,200); #设置比例
$scaleSettings = array("GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE);
$myPicture->drawScale($scaleSettings); #设置图例
$myPicture->drawLegend(580,12,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL)); #设置阴影
$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); #画图表
$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
$settings = array("Surrounding"=>-30,"InnerSurrounding"=>30);
$myPicture->drawBarChart($settings); #递交图片
$myPicture->autoOutput("pictures/example.drawBarChart.simple.png");
?>