<?php // content="text/plain; charset=utf-8" require_once "jpgraph/jpgraph.php"; require_once "jpgraph/jpgraph_bar.php"; require_once "jpgraph/jpgraph_line.php"; require_once "jpgraph/jpgraph_plotline.php"; $datay = array(2, 3, 5, 8.5, 11.5, 6, 3); // Create the graph. $graph = new Graph(460, 400, 'auto'); $graph->SetScale("textlin"); $graph->SetMargin(40, 20, 50, 70); $graph->legend->SetPos(0.5, 0.97, 'center', 'bottom'); $graph->title->Set('Plot line legend'); $graph->title->SetFont(FF_ARIAL, FS_BOLD, 14); $graph->SetTitleBackground('lightblue:1.3', TITLEBKG_STYLE2, TITLEBKG_FRAME_BEVEL); $graph->SetTitleBackgroundFillStyle(TITLEBKG_FILLSTYLE_HSTRIPED, 'lightblue', 'navy'); // Create a bar pot $bplot = new BarPlot($datay); $bplot->value->Show(); $bplot->value->SetFont(FF_VERDANA, FS_BOLD, 8); $bplot->SetValuePos('top'); $bplot->SetLegend('Bar Legend'); $graph->Add($bplot); $pline = new PlotLine(HORIZONTAL, 8, 'red', 2); $pline->SetLegend('Line Legend'); $graph->legend->SetColumns(10); $graph->Add($pline); $graph->Stroke();
public static function liner3Show($data_x, $data_y, $x_title, $y_title, $graph_title) { // echo var_dump($data_x); // echo var_dump($data_y); $graph = new Graph(LENHSIZE, HEISIZE); //创建画布 $graph->img->SetMargin(LEFT, 80, UP, DOWN); //设置统计图所在画布的位置,左边距50、右边距40、上边距30、下边距40,单位为像素 // $graph->yscale->ticks->Set($max_y/2,1); $graph->img->SetAntiAliasing(); //设置折线的平滑状态 $graph->SetScale("textlin", 210, 230); //设置刻度样式 $graph->SetShadow(); //创建画布阴影 $graph->xgrid->Show(); $line = new PlotLine(HORIZONTAL, 220, "red", 2); //设置红色警戒线 $line->SetLegend("警戒线"); $graph->legend->setFont(FF_SIMSUN, FS_BOLD, GRAGHSIZE - 5); $graph->AddLine($line, false); $graph->title->Set($graph_title); //设置标题 $graph->title->SetFont(FF_SIMSUN, FS_BOLD, GRAGHSIZE); //设置标题字体 $graph->SetMarginColor("lightblue"); //设置画布的背景颜色为淡蓝色 $graph->yaxis->title->SetFont(FF_SIMSUN, FS_BOLD); //设置Y轴标题的字体 $graph->xaxis->SetPos("min"); // $graph->yaxis->HideZeroLabel(); // $graph->ygrid->SetFill(true,'#EFEFEF@0.5','#BBCCFF@0.5'); // $a=array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"); //X轴 $graph->xaxis->SetTickLabels($data_x); //设置X轴 $graph->xaxis->SetFont(FF_SIMSUN); //设置X坐标轴的字体 // $graph->yscale->SetGrace(20); $p1 = new LinePlot($data_y); //创建折线图对象 $p1->mark->SetType(MARK_FILLEDCIRCLE); //设置数据坐标点为圆形标记 $p1->mark->SetFillColor("black"); //设置填充的颜色 $p1->mark->SetWidth(3); //设置圆形标记的直径为3像素 $p1->SetColor("blue"); // $p1->SetYMin(0); $graph->Add($p1); $graph->InitializeFrameAndMargin(); $num = rand(0, RAND); // echo var_dump($num); $name = "Histogrm" . $num . ".png"; session_start(); $_SESSION["name"] = $name; // echo var_dump($name); $graph->Stroke($name); return $name; }