php 条形图 树状图 使用GD库生成 非js chart

我们常有的一般都是百度的echart,将数据输出到js里面在渲染出条形图。但是有时候不想把数据输出来,或在项目中不方便使用js情况下!用GD去生成统计图是一个不错的选择!

主要使用https://jpgraph.net项目。

下载地址:https://jpgraph.net/download/

 

形图、饼状图、树状图、等等https://jpgraph.net/features/gallery.php#line1

 

在线示例:https://jpgraph.net/features/src/show-example.php?target=new_line1.php

 

使用示例:https://www.toolnb.com/tools/githubStarRanking.html

 

生成条形图:https://www.toolnb.com/Tools/Api/getGithubHistoryImg.html?guid=801421f6-34fc-09ef-2655-f4a3093440c2

 

代码:


require_once('./jpgraph-4.2.6/src/jpgraph.php');

require_once('./jpgraph-4.2.6/src/jpgraph_line.php');



$datay1 = [2,3,4,5,6];



$graph = new \Graph(260, 180);



$graph->SetScale("textlin");



$theme_class = new \UniversalTheme;



$graph->SetTheme($theme_class);

$graph->img->SetAntiAliasing(false);

$graph->title->Set('Project Star History');

$graph->SetBox(false);



$graph->SetMargin(60, 20, 36, 63);



$graph->img->SetAntiAliasing();



$graph->yaxis->HideZeroLabel();

$graph->yaxis->HideLine(false);

$graph->yaxis->HideTicks(false, false);



$graph->xgrid->Show();

$graph->xgrid->SetLineStyle("solid");

$graph->xaxis->SetTickLabels([1,2,3,4,5]);

$graph->xgrid->SetColor('#E3E3E3');



$p1 = new \LinePlot($datay1);

$graph->Add($p1);

$p1->SetColor("#6495ED");

$p1->SetLegend('Star History');



$graph->legend->SetFrameWeight(1);



$graph->Stroke();

 

参考:https://blog.csdn.net/aoshilang2249/article/details/46956163

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值