php柱状图多系列动态实现
程序员文章站
2022-06-22 13:00:48
```php 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'... ......
<?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(); 本篇为博主原创文章,如需转载请注明出处,谢谢!