JpGraph サンプル

← 一覧に戻る
<?php // content="text/plain; charset=utf-8"
include "jpgraph/jpgraph.php";
include "jpgraph/jpgraph_line.php";
include "jpgraph/jpgraph_scatter.php";
include "jpgraph/jpgraph_regstat.php";

// Original data points
$xdata = array(1,3,5,7,9,12,15,17.1);
$ydata = array(5,1,9,6,4,3,19,12);

// Get the interpolated values by creating
// a new Spline object.
$spline = new Spline($xdata,$ydata);

// For the new data set we want 40 points to
// get a smooth curve.
list($newx,$newy) = $spline->Get(50);

// Create the graph
$g = new Graph(300,200);
$g->title->Set("Natural cubic splines");
$g->subtitle->Set('(Control points shown in red)');


// We need a linlin scale since we provide both
// x and y coordinates for the data points.

// We want 1 decimal for the X-label

// We use a scatterplot to illustrate the original
// contro points.
$splot = new ScatterPlot($ydata,$xdata);


// And a line plot to stroke the smooth curve we got
// from the original control points
$lplot = new LinePlot($newy,$newx);

// Add the plots to the graph and stroke


← 一覧に戻る