1
0
Fork 0
php-coding/12.work1.php

33 lines
1.4 KiB
PHP

<?php
require_once 'jpgraph/jpgraph.php'; //引入jpgraph类库
require_once 'jpgraph/jpgraph_bar.php'; //引入柱状图类库
$datay1 = array(58, 85, 65, 39, 120, 91, 152, 49, 97, 130, 67);
$datay2 = array(18, 35, 101, 69, 138, 131, 112, 149, 88, 60, 77);
$graph = new Graph(600, 300, 'auto'); //创建新的Graph对象 600*300像素 自动调整大小
$graph->SetScale('textlin'); //设置刻度样式 为文本型
//$graph->yaxis->scale->SetGrace(20); //设置Y轴刻度值的上下限值 为20
$graph->SetShadow(); //设置阴影
$graph->img->SetMargin(40, 30, 30, 40); //设置图像边距
$barPlot1 = new BarPlot($datay1); //创建BarPlot对象
$barPlot1->SetFillColor('orange'); //设置柱状图填充颜色
$barPlot1->SetShadow();
$barPlot2 = new BarPlot($datay2);
$barPlot2->SetFillColor('yellow'); //设置柱状图填充颜色
$barPlot2->SetShadow();
$groupBarPlot = new GroupBarPlot(array($barPlot1, $barPlot2));
$groupBarPlot->SetWidth(0.6);
$graph->Add($groupBarPlot);
$graph->SetMarginColor('lightblue'); //设置图像边距颜色 为浅蓝色
$graph->title->Set('应用柱形图依次统计2020年液晶电视、电冰箱的月销量'); //设置图像标题
$graph->title->SetFont(FF_SIMSUN); //设置图像标题字体
$a = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); //设置X轴刻度值
$graph->xaxis->SetTickLabels($a); //设置X轴刻度值
$graph->Stroke(); //输出图像