本文執行個體講述了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程式設計有所協助。