溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

php圖形jpgraph操作的示例分析

發(fā)布時(shí)間:2021-08-05 14:19:25 來源:億速云 閱讀:155 作者:小新 欄目:開發(fā)技術(shù)

小編給大家分享一下php圖形jpgraph操作的示例分析,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

具體如下:

<?php
include ("src/jpgraph.php");
include("src/jpgraph_bar.php");
include ("src/jpgraph_line.php");
//設(shè)置顯示的數(shù)據(jù)數(shù)組;
//調(diào)用類庫
//設(shè)置圖像的大小
$graph = new Graph(400,200,"auto");
$graph->SetScale("textlin");
//設(shè)置圖形的邊距
$graph->img->SetMargin(40,180,40,40);
//設(shè)置圖形的背景圖片,填充方式有:BGIMG_FILLPLOT, BGIMG_FILLFRAME, BGIMG_COPY
$graph->SetBackgroundImage("abc.jpg",BGIMG_FILLPLOT);
$graph->img->SetAngle(45); //設(shè)置圖形在圖像中的角度
//設(shè)置背景圖片的對(duì)比度,must be between -1 <= x <= 1, (0,0)=original image
$graph->AdjBackgroundImage(0,0);
//設(shè)置投影;
//$graph->SetShadow();
//設(shè)置標(biāo)題
$graph->title->Set("test image");
//設(shè)置標(biāo)題字體樣式
$graph->title->SetFont(FF_FONT1,FS_BOLD);
//設(shè)置標(biāo)題的邊距
$graph->title->SetMargin(3);
//設(shè)置圖列的位置
$graph->legend->Pos(0.05,0.5,"right","center");
//設(shè)置圖列的投影,顏色
$graph->legend->SetShadow('darkgray@0.1');
$graph->legend->SetFillColor('lightblue@0.3');
//設(shè)置x軸的標(biāo)記
$graph->xaxis->SetTickLabels($label_x);
//設(shè)置X軸的顯示值的角度;
$graph->xaxis->SetLabelAngle(30);
//設(shè)置x軸標(biāo)題和字體顏色
$graph->xaxis->title->Set('Year 2006');
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetColor('white');
//設(shè)置x軸的字體和顏色
$graph->xaxis->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->SetColor('yellow');
//設(shè)置y軸的字體和顏色
$graph->yaxis->SetFont(FF_FONT1,FS_BOLD);
$graph->yaxis->SetColor('yellow');
//設(shè)置是否顯示格子。默認(rèn)為顯示;
//$graph->ygrid->Show(false);
//設(shè)置格子的顏色和粗細(xì)。值越小,格子越粗。
$graph->ygrid->SetColor('yellow@0.5');
//設(shè)置y軸更優(yōu)美一些
$graph->yaxis->scale->SetGrace(20);
//設(shè)置圖列的數(shù)據(jù)
$bplot1 = new BarPlot($datay1);
$bplot2 = new BarPlot($datay2);
//設(shè)置圖列的填充顏色
$bplot1->SetFillColor('orange@0.4');
$bplot2->SetFillColor('brown@0.4');
//設(shè)置值的格式
$bplot1->value->SetFormat('%d');
//設(shè)置圖列標(biāo)簽
$bplot1->SetLegend('Label 1');
$bplot2->SetLegend('Label 2');
//設(shè)置圖列在圖中的陰影
$bplot1->SetShadow('black@0.4');
$bplot2->SetShadow('black@0.4');
//生成圖列
$gbarplot = new GroupBarPlot(array($bplot1,$bplot2));
$gbarplot->SetWidth(0.9);
$graph->Add($gbarplot);
//生成圖形
$graph->Stroke();
//上面所說的時(shí)在生成柱形圖,當(dāng)生成線性圖時(shí)用下面的方法
$p1 = new LinePlot($datay);
$p1->mark->SetType(MARK_FILLEDCIRCLE);
$p1->mark->SetFillColor("red");
$p1->mark->SetWidth(4);
$p1->SetColor("blue");
$p1->SetCenter();
$p1->SetLegend("Triumph Tiger -98");
$graph->Add($p1);
$p2 = new LinePlot($data2y);
$p2->mark->SetType(MARK_STAR);
$p2->mark->SetFillColor("red");
$p2->mark->SetWidth(4);
$p2->SetColor("red");
$p2->SetCenter();
$p2->SetLegend("New tiger -99");
$graph->Add($p2);
// Style can also be specified as SetStyle([1|2|3|4]) or
// SetStyle("solid"|"dotted"|"dashed"|"lobgdashed")
$lineplot->SetStyle("dashed");//設(shè)置線的樣式
$graph->yaxis->scale->SetGrace(20); //設(shè)置y軸更優(yōu)美一些
?>

2.柱形圖和餅狀圖舉例

if($tag == 1)
{
$graph = new Graph(600,400,"auto");
$graph->SetScale("textlin");
$graph->setMarginColor('lightblue');
$graph->SetShadow();
$graph->setMargin(30,100,30,60);
//設(shè)置標(biāo)題;
$graph->title->set("文章分類匯總");
$graph->title->SetMargin(3);
$graph->title->setfont(FF_SIMSUN,FS_BOLD);
$graph->title->setcolor('black@0.5');
$graph->yaxis->title->SetFont(FF_SIMSUN,FS_BOLD);
$graph->xaxis->title->SetFont(FF_SIMSUN,FS_BOLD);
$graph->xaxis->SetFont(FF_SIMSUN,FS_NORMAL);
$graph->xaxis->SetColor('darkblue','black');
$graph->xaxis->SetTickLabels($name);
$graph->xaxis->SetLabelAngle(30);
$bplot = new BarPlot($article_num);
$bplot->SetFillColor("orange");
$bplot->value->SetFormat('%d');
$bplot->SetShadow('darkgray');
$bplot->value->show();
$graph->legend->SetFont(FF_SIMSUN,FS_BOLD);
$bplot->SetLegend("文章數(shù)");
$graph->Add($bplot);
$graph->Stroke();
}
else
{
$graph2 = new PieGraph(600,400,"auto");
$graph2->SetScale("textlin");
$graph2->SetShadow();
$graph2->title->setFont(FF_SIMSUN,FS_BOLD);
$graph2->title->set("用戶文章餅形圖");
$graph2->setMargin(30,100,30,60);
$p1 = new pieplot3d($article_num);
$p1->setAngle(80);
$p1->setsize(0.5);
$p1->setShadow();
$p1->ExplodeSlice(2);
$p1->SetCenter(0.4);
$graph2->legend->SetFont(FF_SIMSUN,FS_NORMAL);
$graph2->legend->setshadow();
$p1->SetLegends($name);
$graph2->Add($p1);
$graph2->Stroke();
}
//生成本地圖片
$graph->Stroke("路徑/文件名.png");

以上是“php圖形jpgraph操作的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI