Hi there, I am trying to create a graph that contains a straight line and a spline graph that both use the same X axis values. However, the problem I am having is that when I specify the points to use for the spline, the x axis blows out and uses those points as the width.

For example, if my X axis values are from 1 to 10 but my spline data uses 50 points, the X axis will go from 1 to 50 – ignoring the values that I set for the axis.

If I only use 10 points for the spline, the curve does not look like a curve, but the axis is ok.

I can create separate graphs ok. It is only when I combine them that I see this problem.

Is there a way to hard code the x axis? Here is my code:

<?php 
include ("../jpgraph.php"); 
include ("../jpgraph_line.php"); 
include "../jpgraph_scatter.php"; 
include "../jpgraph_regstat.php"; 

// Some data 
$xdata = array(1,2,3,4,5); 
$ydata = array(-1,-1,2,5,8); 
$ydata1 = array(1,2,1.25,2.5,4); 


// Create the graph. These two calls are always required 
$graph = new Graph(500,300,"auto");    
$graph->SetScale("textlin"); $graph->SetMarginColor('lightgreen'); $graph->SetShadow(); // Create the linear plot $lineplot=new LinePlot($ydata); $spline = new Spline($xdata,$ydata1); list($newx,$newy) = $spline->Get(50); $lplot = new LinePlot($newy,$newx); $lineplot->SetColor("blue"); $lplot->SetColor("red"); $graph->title->Set("Examples for graph"); $lineplot->SetLegend("Straight"); $lineplot->SetColor("blue"); $lplot->SetLegend("Spline"); $lplot->SetColor("red"); // Add the plot to the graph $graph->Add($lineplot); $graph->Add($lplot); // Display the graph $graph->Stroke(); ?>

Here is what it looks like:

http://www.petermcphee.com/test/spline.jpg

Any ideas how I can hard code the X axis?

    Write a Reply...