php饼图
A. 有哪些比较好用的php图标插件(生成折线图、柱状图、饼状图) 多多益善 类似highcharts和jpgraph
HighCharts
jqPlot
dygraphs
Protovis
fusioncharts
ECharts
Google Chart Tools
JS Charts
chart.js
jQuery Sparklines
Cubism.js
xcharts
B. php jpgraph 饼图 图例 中文乱码 怎么解决
标题转换成了gb2312 的编码,下边的也转换下就行了.
C. PHP实现柱状图,饼状图
这种图应该可以使用php jpgraph类库来完成,具体的开源类库下载,以及示例、演示情况,你可以访问其官方网站,下载的类库代码里有完整的示例代码。
jpgraphp 官方下载地址
http://jpgraph.net/download/
JpGraph简介
以前用PHP作图时必须要掌握复杂抽象的画图函数,或者借助一些网上下载的花柱形图、饼形图的类来实现。没有一个统一的chart类来实现图表的快速开发。
现在我们有了一个新的选择:JpGraph。专门提供图表的类库。它使得作图变成了一件非常简单的事情,你只需从数据库中取出相关数据,定义标题,图表类型,然后的事情就交给JpGraph,只需掌握为数不多的JpGraph内置函数(可以参照JpGraph附带例子学习),就可以画出非常炫目的图表!
D. 如何使用PHP动态生成饼状图,柱状图和折线图
PHP自带的绘图函数来做特别麻烦,用jpgrah,封装好了的 。传入参数自动生成饼状图,柱状图之类的 特变方便
E. php统计,如何生成饼图算法
饼状图表对于查看一个值占总值的百分比是一个好的方法。我们就用PHP来实现一个饼形图表。
它的设计思想是:
1 接受参数,得到所有数值的和,得到每一个值占数值总和的比例。
2 根据比例计算每一个色块在图中的圆周角度
3 要产生立体效果,只需要用深颜色画出阴影就可以了
F. 怎么不安装类库用php画曲线图和饼图
php本身没有画图功能。都是通过GD库等外部扩展实现的。如果只是单纯的曲线图和饼图,可以考虑使用前端js代码实现,比如iChart等插件都能做出很漂亮的示意图。比GD搞出来的要漂亮,而且是动态的,可以根据点击进行交互。
G. php如何在一个页面同时显示柱状图 折线图 饼图 能给个例子吗
楼住你想要干什么吖,把问题说清楚才行吖
你是想要利用PHP程序生程你所需要的图形
还是在一个网页里面同时显示那几个图形吖.
H. php三维饼图怎么做要调入数据库的数据!请高手指点!不会的别来混经验!
这是个2D的。
其中有一个自定义函数,用于绘制饼图,参数是一个键值对数组。
每项内容是由数组定义的。你调入数据库中的内容后读入数组即可。
前提是你当然要开启GD扩展,要不是没得画得。呵。
<?php
function pie2d($a) //创建自定义函数
{
$im=imagecreate(420,300); //建立图像
$back=imagecolorallocate($im,255,255,200); //背景色
$color[]=imagecolorallocate($im,0,0,255); //定义10个颜色,可以最多处理10项
$color[]=imagecolorallocate($im,255,0,0);
$color[]=imagecolorallocate($im,0,255,0);
$color[]=imagecolorallocate($im,100,100,255);
$color[]=imagecolorallocate($im,255,0,255);
$color[]=imagecolorallocate($im,150,0,0);
$color[]=imagecolorallocate($im,0,0,150);
$color[]=imagecolorallocate($im,0,150,0);
$color[]=imagecolorallocate($im,0,0,0);
$color[]=imagecolorallocate($im,150,150,150);
$value_a=array_values($a); //获取参数数组所有值到新数组
$all=array_sum($value_a); //统计新数组的和
$i=0; //循环标记
foreach($a as $key=>$value) //遍历数组
{
$angle[]=$value/$all*360; //获取当前角度
$str=$key.":".round($value/$all*100,2)."%"; //需要输出的内容
imagestring($im,5,10,($i*20+10),$str,$color[$i]); //画字符串
$i++; //标记自增
}
$s=0; //当前角度标记
$i=0;
foreach($angle as $temp) //遍历所有项角度
{
imagefilledarc($im,285,150,240,120,$s,($s+$temp),$color[$i],4); //画椭圆弧
//imagefillellipse();
$s=$s+$temp; //角度增加为当前角度
$i++;
}
imagepng($im); //输出PNG
imagedestroy($im); //销毁图像
}
$arr=array(
"perfect"=>1,
"excellent"=>2,
"very good"=>4,
"good"=>1,
"not bad"=>1,
"normal"=>1,
"bad"=>1,
"very bad"=>1,
"god save me"=>1,
"hell"=>1
); //定义数组,数组内容为选项内容与选项数量的键值对
$re=pie2d($arr); //调用自定义函数
?>
I. 求php生成饼图的类或例子,图上要有算百分比的
<?php
//公用函数
//把角度转换为弧度
function deg2Arc($degrees) {
return($degrees * (pi()/180.0));
}
//RGB
function getRGB($color){
$R=($color>>16) & 0xff;
$G=($color>>8) & 0xff;
$B=($color) & 0xff;
return (array($R,$G,$B));
}
// 取得在椭圆心为(0,0)的椭圆上 x,y点的值
function pie_point($deg,$va,$vb){
$x= cos(deg2Arc($deg)) * $va;
$y= sin(deg2Arc($deg)) * $vb;
return (array($x, $y));
}
//3D饼图类
class Pie3d{
var $a; //椭圆长半轴
var $b; //椭圆短半轴
var $DataArray; //每个扇形的数据
var $ColorArray; //每个扇形的颜色 要求按照十六进制书写但前面不加0x
//为边缘及阴影为黑色
function Pie3d($pa=150,$pb=100,$sData="10,20,30,40,50", $sColor="#4472A6,#395F8C,#BAC6DE,#91A7CE,#4E7FBA")
{
$this->a=$pa;
$this->b=$pb;
$this->DataArray=split(",",$sData);
$this->ColorArray=split(",",$sColor);
}
function setA($v){
$this->a=$v;
}
function getA(){
return $this->a;
}
function setB($v){
$this->b=$v;
}
function getB(){
return $this->b;
}
function setDataArray($v){
$this->DataArray=split(",",$v);
}
function getDataArray($v){
return $this->DataArray;
}
function setColorArray($v){
$this->ColorArray=split(",",$v);
}
function getColorArray(){
return $this->ColorArray;
}
function DrawPie(){
$image=imagecreate($this->a*2+40,$this->b*2+40);
$PieCenterX=$this->a+10;
$PieCenterY=$this->b+10;
$DoubleA=$this->a*2;
$DoubleB=$this->b*2;
list($R,$G,$B)=getRGB(0);
$colorBorder=imagecolorallocate($image,$R,$G,$B);
$DataNumber=count($this->DataArray);
//$DataTotal
for($i=0;$i<$DataNumber;$i++) $DataTotal+=$this->DataArray[$i]; //算出数据和
//填充背境
imagefill($image, 0, 0, imagecolorallocate($image, 0xFF, 0xFF, 0xFF));
/*
** 画每一个扇形
*/
$Degrees = 0;
for($i = 0; $i < $DataNumber; $i++){
$StartDegrees = round($Degrees);
$Degrees += (($this->DataArray[$i]/$DataTotal)*360);
$EndDegrees = round($Degrees);
$percent = number_format($this->DataArray[$i]/$DataTotal*100, 1);
list($R,$G,$B)=getRGB(hexdec($this->ColorArray[$i]));
$CurrentColor=imagecolorallocate($image,$R,$G,$B);
if ($R>60 and $R<256) $R=$R-60;
if ($G>60 and $G<256) $G=$G-60;
if ($B>60 and $B<256) $B=$B-60;
$CurrentDarkColor=imagecolorallocate($image,$R,$G,$B);
//画扇形弧
imagearc($image,$PieCenterX,$PieCenterY,$DoubleA,$DoubleB,$StartDegrees,$EndDegrees,$CurrentColor);
//画直线
list($ArcX, $ArcY) = pie_point($StartDegrees , $this->a , $this->b);
imageline($image,$PieCenterX,$PieCenterY,floor($PieCenterX + $ArcX),floor($PieCenterY + $ArcY),$CurrentColor);
//画直线
list($ArcX, $ArcY) = pie_point($EndDegrees,$this->a , $this->b);
imageline($image,$PieCenterX,$PieCenterY,ceil($PieCenterX + $ArcX),ceil($PieCenterY + $ArcY),$CurrentColor);
//填充扇形
$MidPoint = round((($EndDegrees - $StartDegrees)/2) + $StartDegrees);
list($ArcX, $ArcY) = Pie_point($MidPoint, $this->a*3/4 , $this->b*3/4);
imagefilltoborder($image,floor($PieCenterX + $ArcX),floor($PieCenterY + $ArcY), $CurrentColor,$CurrentColor);
imagestring($image,2,floor($PieCenterX + $ArcX-5),floor($PieCenterY + $ArcY-5),$percent."%",$colorBorder);
//画阴影
if ($StartDegrees>=0 and $StartDegrees<=180){
if($EndDegrees<=180){
for($k = 1; $k < 15; $k++)
imagearc($image,$PieCenterX, $PieCenterY+$k,$DoubleA, $DoubleB, $StartDegrees, $EndDegrees, $CurrentDarkColor);
}else{
for($k = 1; $k < 15; $k++)
imagearc($image,$PieCenterX, $PieCenterY+$k,$DoubleA, $DoubleB, $StartDegrees, 180, $CurrentDarkColor);
}
}
}
/*到此脚本已经生了一幅图像了
**现在需要的是把它发到浏览器上,重要的一点是要将标头发给浏览器,让它知道是一个GIF文件。不然的话你只能看到一堆奇怪的乱码
*/
//输出生成的图片
header("Content-type: image/gif");
imagegif($image);
imagedestroy($image);
}//End drawPie()
}//End class
//实现
$objp = new Pie3d();
$objp->DrawPie();
?>
J. 请问jpgraph饼图如何实现如图中的红圈所圈内容一行显示8个项目谢谢
配置
首先需要注意的是:要想适用jpgraph,你的PHP必须开启了GD2扩展。
在jpgraph.php中有以下这样一段代码是设置字体文件路径的
if (!defined('TTF_DIR')) {
if (strstr( PHP_OS, 'WIN') ) {
$sroot = getenv('SystemRoot');
if( empty($sroot) ) {
$t = new ErrMsgText();
$msg = $t->Get(12,$file,$lineno);
die($msg);
}
else {
define('TTF_DIR', $sroot.'/fonts/');
}
} else {
define('TTF_DIR','/usr/share/fonts/truetype/');ç(我的作法是将windows下的fonts文件夹下的字体全部COPY到/usr/local/fonts/truetype)
}
}
要支持中文需要用到simhei.ttf和simsun.ttc这两个字体,在使用中文的时候需要使用SetFont(FF_SIMSUN,FS_BOLD)设置字体。
如果你的文件编码为utf-8,修改方法如下:
代码:
方法一,在程序中修改
$title="流量图";
$title = iconv("UTF-8", "gb2312", $title);
$graph->title->Set($title);
方法二,修改源文件jpgraph_ttf.inc.php
在第99-106行,改成下面这样子
elseif( $aFF === FF_SIMSUN ) {
// Do Chinese conversion
/*
if( $this->g2312 == null ) {
include_once 'jpgraph_gb2312.php' ;
$this->g2312 = new GB2312toUTF8();
}
return $this->g2312->gb2utf8($aTxt);
*/
return $aTxt;
}
jpgraph默认显示汉字时是把汉字编码认为gb2312,转化为utf-8以后再显示。
这样的话,如果你的文件编码是gb2312,SetFont方法的第一个参数为FF_SIMSUN即可。
如果你是utf-8编码你还需要先把汉字编码转化为gb2312,这样你的汉字才可以正常显示。
使用
可以参照jpgraph-2.3.4srcExamples中的例子。下面是一些常用的:
$graph->title->Set(‘设置图表的标题’);
$graph->xaxis->title->Set("设置X轴的标题");
$graph->yaxis->title->Set("设置Y轴的标题");
//设置字体如果是中文,第一个参数一般设置为FF_SIMSUN
SetFont(FF_SIMSUN,FS_BOLD,14);
//如设置图表标题的字体
$graph->title->SetFont(FF_SIMSUN,FS_BOLD,14);
//设置颜色
SetColor('red');
Example:
例1. php Jpgraph绘制简单的X-Y坐标图
<?php
include ("../jpgraph.php");
include ("../jpgraph_line.php");
//将要用于图表创建的数据存放在数组中
$data=array(19,23,34,38,45,67,71,78,85,90,96,145);
$graph=newGraph(500,300);//创建新的Graph对象
$graph->SetScale("textlin");//设置刻度样式
$graph->img->SetMargin(30,30,80,30);//设置图表边界
$graph->title->Set("CDNTrafficTotal");//设置图表标题
$graph->title->SetColor("blue");
$graph->title->SetMargin(20);
//Createthelinearplot
$lineplot=newLinePlot($data);//创建新的LinePlot对象
$lineplot->SetLegend("Line(Mbits)");//设置图例文字
$lineplot->SetColor("red");//设置曲线的颜色
//Addtheplottothegraph
$graph->Add($lineplot);//在统计图上绘制曲线
//Displaythegraph
$graph->Stroke();//输出图像
?>
例6.
index.html
<html>
<head>
<title>CDN流量查询系统统计</title>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
<mce:styletype="text/css"><!--
.style1{
font-size:16px;
font-weight:bold;
}
--></mce:style><styletype="text/css"mce_bogus="1">.style1{
font-size:16px;
font-weight:bold;
}</style>
</head>
<body>
<formname="form1"method="get"action="result.php">
<palign="center"class="style1">CDN流量查询系统统计</p>
<tablewidth="300"border="1"align="center"cellpadding="3"cellspacing="3">
<tr>
<tdwidth="85"><strong>查询年份</strong></td>
<tdwidth="188"><selectname="acct_yr"id="acct_yr">
<optionvalue="2009"selected>2008</option>
<optionvalue="2009"selected>2009</option>
</select></td>
</tr>
<tr>
<td><strong>起始月份</strong></td>
<td><selectname="start_mth"id="start_mth">
<optionselected>01</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
<option>06</option>
<option>07</option>
<option>08</option>
<option>09</option>
<option>10</option>
<option>11</option>
<option>12</option>
</select></td>
</tr>
<tr>
<td><strong>终止月份</strong></td>
<td><selectname="end_mth"id="end_mth">
<option>01</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
<option>06</option>
<option>07</option>
<option>08</option>
<option>09</option>
<option>10</option>
<option>11</option>
<optionselected>12</option>
</select></td>
</tr>
<tr>
<td><strong>统计图类别</strong></td>
<td><selectname="graph"id="graph">
<optionvalue="1"selected>线型图</option>
<optionvalue="2">柱形图</option>
<optionvalue="3">饼图</option>
<optionvalue="4">3D饼图</option>
</select></td>
</tr>
</table>
<palign="center">
<inputtype="submit"value="Submit">
<inputtype="reset"name="Submit2"value="Reset">
</p>
</form>
</body>
</html>
case1:
$graph=newGraph(400,300);//创建新的Graph对象
$graph->SetScale("textlin");//设置刻度样式
$graph->img->SetMargin(30,30,80,30);//设置图表边界
$graph->title->SetFont(FF_SIMSUN,FS_BOLD);//设置字体
$graph->title->Set("CDN流量查询");//设置图表标题
$lineplot=newLinePlot($data);
$lineplot->SetLegend("Line");
$lineplot->SetColor("red");
$graph->Add($lineplot);
break;
case2:
$graph=newGraph(400,300);
$graph->SetScale("textlin");
$graph->SetShadow();
$graph->img->SetMargin(40,30,20,40);
$barplot=newBarPlot($data);//创建BarPlot对象
$barplot->SetFillColor('blue');//设置颜色
$barplot->value->Show();//设置显示数字
$graph->Add($barplot);//将柱形图添加到图像中
$graph->title->Set("CDN流量查询");//设置标题和X-Y轴标题
$graph->xaxis->title->Set("月份");
$graph->yaxis->title->Set("流量(Gbits)");
$graph->title->SetFont(FF_SIMSUN,FS_BOLD);//设置字体
$graph->yaxis->title->SetFont(FF_SIMSUN,FS_BOLD);
$graph->xaxis->title->SetFont(FF_SIMSUN,FS_BOLD);
break;
case3:
$graph=newPieGraph(400,300);
$graph->SetShadow();
$graph->title->Set("CDN流量查询");
$graph->title->SetFont(FF_SIMSUN,FS_BOLD);
$pieplot=newhttps://www.guwengl.com#data);
$pieplot->SetLegends($gDateLocale->GetShortMonth());//设置图例
$graph->Add($pieplot);
break;
default:
echo"graph参数错误";
exit;
}
$graph->Stroke();
?>