<?php //XY座標圖 require_once("../src/jpgraph.php"); require_once("../src/jpgraph_bar.php"); //柱形圖模擬數據 $data = array(0 => -21, 1 => -3, 2 => 12, 3 => 19, 4 => 23, 5 => 29, 6 => 30, 7 => 22, 8 => 26, 9 => 18, 10 => 5, 11 => -10); //1.建立畫布 $graph = new Graph(600, 400); //2.設置橫座標刻度樣式 $graph->SetScale("textlin"); //設置統計圖邊界範圍 $graph->img->SetMargin(30,30,80,30); //設置統計圖標題 $graph->title->SetFont(FF_CHINESE); //--設置支持中文標題 $graph->title->Set("BarPlot test"); //獲得柱形圖對象 $barPlot=new BarPlot($data); //設置柱形圖圖例 $barPlot->SetLegend("柱形圖"); //顯示柱形圖表明數據的值 $barPlot->value->show(); //將柱形圖加入到背景圖 $graph->Add($barPlot); //設置柱形圖填充顏色 $barPlot->setfillcolor("yellow"); //設置邊框顏色 $barPlot->Setcolor("red"); //將柱形圖輸出到瀏覽器 $graph->Stroke();
輸出:php