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

25 lines
1.3 KiB
PHP

<?php
require_once 'jpgraph/jpgraph.php'; //引入jpgraph类库
require_once 'jpgraph/jpgraph_bar.php'; //引入柱状图类库
$datay = array(160, 180, 203, 289, 405, 488, 489, 408, 299, 166, 187, 105); //销量数据
$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); //设置图像边距
$barPlot = new BarPlot($datay); //创建BarPlot对象
$barPlot->SetFillColor('orange'); //设置柱状图填充颜色
$graph->Add($barPlot); //将柱状图添加到图像中
$barPlot->value->Show(); //设置显示数字
$barPlot->value->SetFormat('%d'); //设置数字显示格式
$graph->SetMarginColor('lightblue'); //设置图像边距颜色 为浅蓝色
$graph->title->Set('销量统计'); //设置图像标题
$a = array('1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月',
'11月', '12月'); //设置X轴刻度值
$graph->xaxis->SetTickLabels($a); //设置X轴刻度值
$graph->title->SetFont(FF_SIMSUN); //设置图像标题字体
$graph->xaxis->SetFont(FF_SIMSUN); //设置X轴刻度值字体
$graph->Stroke(); //输出图像