PHPlot 是純 PHP 繪圖庫,基於 GD,支援長條圖、折線圖、圓餅圖、面積圖、散佈圖等,輸出 PNG/JPG/GIF。適合動態生成報表圖表。
SetDataType($type):text-data(X 軸標籤+多資料集)、data-data(X 值+Y 值)、data-data-error(含誤差)SetDataValues(array $data):設定資料陣列SetPlotType($type):bars, lines, linepoints, area, points, pie, thinbarline, squared, stackedbars, stackedareaSetFileFormat($fmt):PNG, JPEG, GIFSetUseTTF($bool):是否使用 TrueType 字型SetDefaultTTFont($path):設定 TTF 字型檔路徑SetPlotAreaWorld($xmin, $ymin, $xmax, $ymax):設定資料座標範圍SetPlotAreaPixels($x1, $y1, $x2, $y2):設定繪圖區像素範圍SetXLabelAngle($angle)、SetXTitle($title)、SetYTitle($title)SetTitle($title):主標題SetLegend(array $labels):圖例標籤SetLegendWorld($x, $y):圖例位置(世界座標)SetXTickPos/LabelPos('none'|'plotup'|'plotdown'):X 軸刻度/標籤位置SetPrecisionX/Y($digits):座標精度SetBackgroundColor($color)、SetPlotBgColor($color)SetGridColor($color)、SetLightGridColor($color)SetLineWidth($width)、SetLineStyles($styles)SetPointShape($shape):rect, circle, diamond, triangle, dot, line, halflineSetPointSize($size)SetTextColor($color)、SetTitleColor($color)、SetTickColor($color)SetDrawPlotAreaBackground(true)SetPlotBorderType('full'|'none'|'sides')require_once 'phplot.php';
$data = [
['2001', 60, 35, 20],
['2002', 65, 30, 30],
['2003', 70, 25, 40],
['2004', 72, 20, 60],
['2005', 75, 15, 70],
['2006', 77, 10, 80],
['2007', 80, 5, 90],
];
$p = new PHPlot(600, 400);
$p->SetDefaultTTFont('./arial.ttf');
$p->SetTitle('PHPlot Customer Satisfaction (estimated)');
$p->SetDataType('text-data');
$p->SetDataValues($data);
$p->SetPlotType('bars');
$p->SetPlotAreaWorld(0, 0, 7, 100);
$p->SetBackgroundColor('#ffffcc');
$p->SetDrawPlotAreaBackground(true);
$p->SetPlotBgColor('#ffffff');
$p->SetPlotBorderType('full');
$p->SetLegend(['Features', 'Bugs', 'Happy Users']);
$p->SetLegendWorld(0.1, 95);
$p->SetXDataLabelPos('plotdown');
$p->SetXTickPos('none');
$p->SetXTickLabelPos('none');
$p->SetYTickPos('none');
$p->SetYTickLabelPos('none');
$p->DrawGraph();