PHP 그래픽 jpgraph 작업에 대한 자세한 설명

墨辰丷
풀어 주다: 2023-03-27 21:18:01
원래의
2747명이 탐색했습니다.

이 글은 주로 PHP 그래픽 jpgraph의 작동을 소개하고, jpgraph 그래픽 라이브러리를 기반으로 PHP 관련 작동 기술을 분석하여 구체적인 예제를 기반으로 그래픽 그리기를 구현합니다. 도움이 필요한 친구들은 참고할 수 있습니다

자세한 내용은 다음과 같습니다.

<?php
include ("src/jpgraph.php");
include("src/jpgraph_bar.php");
include ("src/jpgraph_line.php");
//设置显示的数据数组;
//调用类库
//设置图像的大小
$graph = new Graph(400,200,"auto");
$graph->SetScale("textlin");
//设置图形的边距
$graph->img->SetMargin(40,180,40,40);
//设置图形的背景图片,填充方式有:BGIMG_FILLPLOT, BGIMG_FILLFRAME, BGIMG_COPY
$graph->SetBackgroundImage("abc.jpg",BGIMG_FILLPLOT);
$graph->img->SetAngle(45); //设置图形在图像中的角度
//设置背景图片的对比度,must be between -1 <= x <= 1, (0,0)=original image
$graph->AdjBackgroundImage(0,0);
//设置投影;
//$graph->SetShadow();
//设置标题
$graph->title->Set("test image");
//设置标题字体样式
$graph->title->SetFont(FF_FONT1,FS_BOLD);
//设置标题的边距
$graph->title->SetMargin(3);
//设置图列的位置
$graph->legend->Pos(0.05,0.5,"right","center");
//设置图列的投影,颜色
$graph->legend->SetShadow(&#39;darkgray@0.1&#39;);
$graph->legend->SetFillColor(&#39;lightblue@0.3&#39;);
//设置x轴的标记
$graph->xaxis->SetTickLabels($label_x);
//设置X轴的显示值的角度;
$graph->xaxis->SetLabelAngle(30);
//设置x轴标题和字体颜色
$graph->xaxis->title->Set(&#39;Year 2006&#39;);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetColor(&#39;white&#39;);
//设置x轴的字体和颜色
$graph->xaxis->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->SetColor(&#39;yellow&#39;);
//设置y轴的字体和颜色
$graph->yaxis->SetFont(FF_FONT1,FS_BOLD);
$graph->yaxis->SetColor(&#39;yellow&#39;);
//设置是否显示格子。默认为显示;
//$graph->ygrid->Show(false);
//设置格子的颜色和粗细。值越小,格子越粗。
$graph->ygrid->SetColor(&#39;yellow@0.5&#39;);
//设置y轴更优美一些
$graph->yaxis->scale->SetGrace(20);
//设置图列的数据
$bplot1 = new BarPlot($datay1);
$bplot2 = new BarPlot($datay2);
//设置图列的填充颜色
$bplot1->SetFillColor(&#39;orange@0.4&#39;);
$bplot2->SetFillColor(&#39;brown@0.4&#39;);
//设置值的格式
$bplot1->value->SetFormat(&#39;%d&#39;);
//设置图列标签
$bplot1->SetLegend(&#39;Label 1&#39;);
$bplot2->SetLegend(&#39;Label 2&#39;);
//设置图列在图中的阴影
$bplot1->SetShadow(&#39;black@0.4&#39;);
$bplot2->SetShadow(&#39;black@0.4&#39;);
//生成图列
$gbarplot = new GroupBarPlot(array($bplot1,$bplot2));
$gbarplot->SetWidth(0.9);
$graph->Add($gbarplot);
//生成图形
$graph->Stroke();
//上面所说的时在生成柱形图,当生成线性图时用下面的方法
$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");//设置线的样式
$graph->yaxis->scale->SetGrace(20); //设置y轴更优美一些
?>
로그인 후 복사

2 .열차트 및 원형차트의 예

if($tag == 1)
{
$graph = new Graph(600,400,"auto");
$graph->SetScale("textlin");
$graph->setMarginColor(&#39;lightblue&#39;);
$graph->SetShadow();
$graph->setMargin(30,100,30,60);
//设置标题;
$graph->title->set("文章分类汇总");
$graph->title->SetMargin(3);
$graph->title->setfont(FF_SIMSUN,FS_BOLD);
$graph->title->setcolor(&#39;black@0.5&#39;);
$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(&#39;darkblue&#39;,&#39;black&#39;);
$graph->xaxis->SetTickLabels($name);
$graph->xaxis->SetLabelAngle(30);
$bplot = new BarPlot($article_num);
$bplot->SetFillColor("orange");
$bplot->value->SetFormat(&#39;%d&#39;);
$bplot->SetShadow(&#39;darkgray&#39;);
$bplot->value->show();
$graph->legend->SetFont(FF_SIMSUN,FS_BOLD);
$bplot->SetLegend("文章数");
$graph->Add($bplot);
$graph->Stroke();
}
else
{
$graph1 = new PieGraph(600,400,"auto");
$graph1->SetScale("textlin");
$graph1->SetShadow();
$graph1->title->setFont(FF_SIMSUN,FS_BOLD);
$graph1->title->set("用户文章饼形图");
$graph1->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);
$graph1->legend->SetFont(FF_SIMSUN,FS_NORMAL);
$graph1->legend->setshadow();
$p1->SetLegends($name);
$graph1->Add($p1);
$graph1->Stroke();
}
//生成本地图片
$graph->Stroke("路径/文件名.png");
로그인 후 복사

위 내용은 이 글의 전체 내용입니다. 모든 분들의 학습에 도움이 되기를 바랍니다.


관련 권장 사항:

php Jpgraph를 사용하여 좌표 차트를 그리는 방법에 대한 고급 기사

php Jpgraph를 사용하여 좌표 차트를 그리는 방법에 대한 기본 기사

PHP 그래픽 작업 Jpgraph

위 내용은 PHP 그래픽 jpgraph 작업에 대한 자세한 설명의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!