source: trunk/xgraph/jpgraph/Examples/bezierex1.php @ 42

Last change on this file since 42 was 42, checked in by marrucho, 10 years ago
File size: 1.5 KB
Line 
1<?php // content="text/plain; charset=utf-8"
2require_once ('jpgraph/jpgraph.php');
3require_once ('jpgraph/jpgraph_line.php');
4require_once ('jpgraph/jpgraph_scatter.php');
5require_once ('jpgraph/jpgraph_regstat.php');
6
7// Original data points
8$xdata = array(1,3,12,15);
9$ydata = array(5,15,2,19);
10
11// Get the interpolated values by creating
12// a new Spline object.
13$bez = new Bezier($xdata,$ydata);
14
15// For the new data set we want 40 points to
16// get a smooth curve.
17list($newx,$newy) = $bez->Get(50);
18
19// Create the graph
20$g = new Graph(300,200);
21$g->SetMargin(30,20,40,30);
22$g->title->Set("Bezier interpolation");
23$g->title->SetFont(FF_ARIAL,FS_NORMAL,12);
24$g->subtitle->Set('(Control points shown in red)');
25$g->subtitle->SetColor('darkred');
26$g->SetMarginColor('lightblue');
27
28//$g->img->SetAntiAliasing();
29
30// We need a linlin scale since we provide both
31// x and y coordinates for the data points.
32$g->SetScale('linlin');
33
34// We want 1 decimal for the X-label
35$g->xaxis->SetLabelFormat('%1.1f');
36
37// We use a scatterplot to illustrate the original
38// contro points.
39$bplot = new ScatterPlot($ydata,$xdata);
40$bplot->mark->SetFillColor('red@0.3');
41$bplot->mark->SetColor('red@0.5');
42
43// And a line plot to stroke the smooth curve we got
44// from the original control points
45$lplot = new LinePlot($newy,$newx);
46$lplot->SetColor('navy');
47
48// Add the plots to the graph and stroke
49$g->Add($lplot);
50$g->Add($bplot);
51$g->Stroke();
52
53?>
54
Note: See TracBrowser for help on using the repository browser.