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

41 lines
1.4 KiB
PHP

<?php
require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_pie.php';
require_once 'jpgraph/jpgraph_pie3d.php';
function createPiePlot3D($data, $legends, $centerX, $centerY, $title): PiePlot3D
{
$piePlot3D = new PiePlot3D($data);
$piePlot3D->SetLegends($legends);
$piePlot3D->SetSize(0.13);
$piePlot3D->SetCenter($centerX, $centerY);
$piePlot3D->title->Set($title);
$piePlot3D->title->SetFont(FF_SIMSUN,FS_BOLD);
$piePlot3D->title->SetMargin(10,40,10,40);
return $piePlot3D;
}
$data1 = array(40,21,17,14,23);
$data2 = array(60,54,107,24,83);
$data3 = array(52,151,99,110,223);
$data4 = array(70,181,117,114,33);
$year_data = array("2016年","2017年","2018年","2019年");
$arr = array("大豆","玉米","水稻","小麦","高梁");
$title = '统计2016年、2017年、2018年、2019年农产品的产量比率';
$pieGraph = new PieGraph(600, 350, 'auto');
$pieGraph->SetShadow();
$pieGraph->title->Set($title);
$pieGraph->title->SetFont(FF_SIMSUN, FS_BOLD);
$pieGraph->legend->SetFont(FF_SIMSUN, FS_BOLD);
$piePlot3D1 = createPiePlot3D($data1, $arr, 0.25, 0.25, "2016年");
$piePlot3D2 = createPiePlot3D($data2, $arr, 0.65, 0.25, "2017年");
$piePlot3D3 = createPiePlot3D($data3, $arr, 0.25, 0.65, "2018年");
$piePlot3D4 = createPiePlot3D($data4, $arr, 0.65, 0.65, "2019年");
$pieGraph->Add($piePlot3D1);
$pieGraph->Add($piePlot3D2);
$pieGraph->Add($piePlot3D3);
$pieGraph->Add($piePlot3D4);
$pieGraph->Stroke();