php 实现柱状图,php柱状图多系列动态实现

require_once 'data.php';

require_once 'jpgraph/src/jpgraph.php';

require_once"jpgraph/src/jpgraph_bar.php";

$arr1=$a->sum('answer','answer_id=1');

$arr2=$a->sum('answer','answer_id=2');

$arr3=$a->sum('answer','answer_id=3');

$arr4=$a->sum('answer','answer_id=4');

$arr5=$a->sum('answer','answer_id=5');

$arr6=$a->sum('answer','answer_id=6');

for($i=0;$i<10;$i++){

$datay1[$i]=$arr1[$i]['numbers'];

$datay2[$i]=$arr2[$i]['numbers'];

$datay3[$i]=$arr3[$i]['numbers'];

$datay4[$i]=$arr4[$i]['numbers'];

$datay5[$i]=$arr5[$i]['numbers'];

$datay6[$i]=$arr6[$i]['numbers'];

}

//设置显示的数据数组;

//调用类库

$x = array("1","2","3","4","5","6","7","8","9","10");

//设置图像的大小

$graph = new Graph(1000,500); //创建新的Graph对象

$graph->SetScale("textlin"); //刻度样式

$graph->SetShadow(); //设置阴影

$graph->img->SetMargin(40,30,40,50); //设置边距

$graph->graph_theme = null; //设置主题为null,否则value->Show(); 无效

$ybplot1 = new BarPlot($datay1); //创建BarPlot对象

$ybplot2 = new BarPlot($datay2);

$ybplot3 = new BarPlot($datay3);

$ybplot4 = new BarPlot($datay4);

$ybplot5 = new BarPlot($datay5);

$ybplot6 = new BarPlot($datay6);

$barplot = new GroupBarPlot(array($ybplot1,$ybplot2,$ybplot3,$ybplot4,$ybplot5,$ybplot6));

$ybplot1->SetFillColor('red'); //设置颜色

$ybplot2->SetFillColor('blue'); //设置颜色

$ybplot3->SetFillColor('green'); //设置颜色

$ybplot4->SetFillColor('gray'); //设置颜色

$ybplot5->SetFillColor('orange');

$ybplot6->SetFillColor('#000');

$ybplot1->value->Show(); //设置显示数字

$ybplot2->value->Show(); //设置显示数字

$ybplot3->value->Show(); //设置显示数字

$ybplot4->value->Show(); //设置显示数字

//$ybplot5->value->show();

//$ybplot6->value->show();

$graph->Add($barplot); //将柱形图添加到图像中

$graph->title->Set("统计");

$graph->xaxis->title->Set("题目"); //设置标题和X-Y轴标题

$graph->yaxis->title->Set("人数(个人)");

$graph->title->SetColor("black");

$graph->title->SetMargin(10);

$graph->xaxis->title->SetMargin(3);

$graph->yaxis->title->SetMargin(-5);

$graph->xaxis->SetTickLabels($x);

$graph->title->SetFont(FF_SIMSUN,FS_BOLD); //设置字体

$graph->yaxis->title->SetFont(FF_SIMSUN,FS_BOLD);

$graph->xaxis->title->SetFont(FF_SIMSUN,FS_BOLD);

$graph->xaxis->SetFont(FF_SIMSUN,FS_BOLD);

$graph->Stroke();

本篇为博主原创文章,如需转载请注明出处,谢谢!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值