本文實例講述了php使用Jpgraph繪制復雜X-Y坐標圖的方法。分享給大家供大家參考。具體實現方法如下:
<?php include ("src/jpgraph.php"); include ("src/jpgraph_line.php"); $data1 = array(19,23,34,38,45,67,71,78,85,87,90,96); //第一條曲線的數組 $data2 = array(523,634,371,278,685,587,490,256,398,545,367,577); //第二條曲線的數組 $graph = new Graph(400,300); //創建新的Graph對象 $graph->SetScale("textlin"); $graph->SetY2Scale("lin"); $graph->SetShadow(); //設置圖像的陰影樣式 $graph->img->SetMargin(40,50,20,70); //設置圖像邊距 $graph->title->Set("年度收支表"); //設置圖像標題 $lineplot1=new LinePlot($data1); //創建設置兩條曲線對象 $lineplot2=new LinePlot($data2); $graph->Add($lineplot1); //將曲線放置到圖像上 $graph->AddY2($lineplot2); $graph->xaxis->title->Set("月份"); //設置坐標軸名稱 $graph->yaxis->title->Set("兆美元"); $graph->y2axis->title->Set("兆美元"); $graph->title->SetFont(FF_SIMSUN,FS_BOLD); //設置字體 $graph->yaxis->title->SetFont(FF_SIMSUN,FS_BOLD); $graph->y2axis->title->SetFont(FF_SIMSUN,FS_BOLD); $graph->xaxis->title->SetFont(FF_SIMSUN,FS_BOLD); $lineplot1->SetColor("red"); //設置顏色 $lineplot2->SetColor("blue"); $lineplot1->SetLegend("Cost Amount"); //設置圖例名稱 $lineplot2->SetLegend("Revenue Amount"); $graph->legend->SetLayout(LEGEND_HOR); //設置圖例樣式和位置 $graph->legend->Pos(0.4,0.95,"center","bottom"); $graph->Stroke(); //輸出圖像 ?>
運行效果如下圖所示:
希望本文所述對大家的php程序設計有所幫助。