require_once 'jpgraph/jpgraph.php'; require_once 'jpgraph/jpgraph_line.php'; $ydata = array(11, 3, 8, 12, 5, 1, 9, 13, 5, 7); $y2data = array(354, 200, 265, 99, 111, 91, 198, 225, 293, 251); $graph = new Graph\Graph(350, 300); $graph->SetAngle(40); $graph->img->SetMargin(80, 80, 80, 80); $graph->SetScale("textlin"); $graph->SetY2Scale("lin"); $graph->SetShadow(); // Create the linear plot $lineplot = new Plot\LinePlot($ydata); $lineplot2 = new Plot\LinePlot($y2data); // Add the plot to the graph $graph->Add($lineplot); $graph->AddY2($lineplot2); $lineplot2->SetColor("orange"); $lineplot2->SetWeight(2); $graph->y2axis->SetColor("orange"); $graph->title->Set("Example 1 rotated graph (40 degree)"); $graph->legend->Pos(0.05, 0.1, "right", "top"); $graph->title->SetFont(FF_FONT1, FS_BOLD); $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD); $lineplot->SetColor("blue"); $lineplot->SetWeight(2); $lineplot2->SetColor("orange"); $lineplot2->SetWeight(2); $graph->yaxis->SetColor("blue"); $lineplot->SetLegend("Plot 1"); $lineplot2->SetLegend("Plot 2");
// Setup the scales for X,Y and Y2 axis $graph->SetScale("intlin"); // X and Y axis $graph->SetY2Scale("lin"); // Y2 axis // Overall graph title $graph->title->Set('Synchronized Y & Y2 scales'); $graph->title->SetFont(FF_ARIAL, FS_BOLD, 12); // Title for X-axis $graph->xaxis->title->Set('Measurement'); $graph->xaxis->title->SetMargin(5); $graph->xaxis->title->SetFont(FF_ARIAL, FS_NORMAL, 11); // Create Y data set $lplot = new Plot\LinePlot($datay); $graph->yaxis->title->Set('Celcius (C)'); $graph->yaxis->title->SetMargin(5); $graph->yaxis->title->SetFont(FF_ARIAL, FS_NORMAL, 11); // ... and add the plot to the Y-axis $graph->Add($lplot); // Create Y2 scale data set $l2plot = new Plot\LinePlot($datay); $l2plot->SetWeight(0); $graph->y2axis->title->Set('Fahrenheit (F)'); $graph->y2axis->title->SetMargin(5); // Some extra margin to clear labels $graph->y2axis->title->SetFont(FF_ARIAL, FS_NORMAL, 11); $graph->y2axis->SetLabelFormatCallback('toFahrenheit'); $graph->y2axis->SetColor('navy'); // ... and add the plot to the Y2-axis $graph->AddY2($l2plot); $graph->Stroke();
$graph->SetMargin(50, 50, 60, 40); $graph->SetMarginColor('darkblue'); $graph->SetColor('darkblue'); // Setup titles $graph->title->Set("Inverting both Y-axis"); $graph->title->SetFont(FF_FONT1, FS_BOLD); $graph->title->SetColor("white"); $graph->subtitle->Set("(Negated Y & Y2 axis)"); $graph->subtitle->SetFont(FF_FONT1, FS_NORMAL); $graph->subtitle->SetColor("white"); // Setup axis $graph->yaxis->SetLabelFormatCallback("_cb_negate"); $graph->xaxis->SetColor("lightblue", "white"); $graph->yaxis->SetColor("lightblue", "white"); $graph->ygrid->SetColor("blue"); // Setup Y2 axis $graph->y2axis->SetLabelFormatCallback("_cb_negate"); $graph->y2axis->SetColor("darkred", "white"); $graph->y2scale->SetAutoMax(0); // To make sure it starts with 0 // Setup plot 1 $lp1 = new Plot\LinePlot($ydata); $lp1->SetColor("yellow"); $lp1->SetWeight(2); $graph->Add($lp1); // Setup plot 2 $lp2 = new Plot\LinePlot($y2data); $lp2->SetColor("darkred"); $lp2->SetWeight(2); $graph->AddY2($lp2); $graph->Stroke();
$graph = new Graph\Graph(500, 300); $graph->SetScale("loglog"); $graph->SetY2Scale("lin"); $graph->y2axis->SetColor("blue", "blue"); $graph->img->SetMargin(50, 70, 40, 50); $graph->title->Set("Geoelektrik"); $graph->xaxis->title->Set("Auslage ab/2 [m]"); $graph->yaxis->title->Set("rho_s [Ohm m]"); $graph->y2axis->title->Set("mn/2 [m]"); $graph->y2axis->title->SetColor("blue"); $graph->y2axis->SetTitleMargin(35); $graph->title->SetFont(FF_FONT1, FS_BOLD); $graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD); $graph->xgrid->Show(true, true); $graph->ygrid->Show(true, true); // Create the linear plot $lineplot = new Plot\LinePlot($rhos, $ab2); $lineplot->SetWeight(1); $lineplot->mark->SetType(MARK_FILLEDCIRCLE); $lineplot->mark->SetWidth(2); // Create scatter plot $scplot = new ScatterPlot($mn2, $ab2); $scplot->mark->SetType(MARK_FILLEDCIRCLE); $scplot->mark->SetColor("blue"); $scplot->mark->SetWidth(2); // Add plots to the graph $graph->AddY2($scplot); $graph->Add($lineplot); // Display the graph $graph->Stroke();