Question

I'm using JpGraph to graph some data. When I use the SetScale function to force a y-axis range the output visually overflows the graph area. I would like to have the output cropped to the graph area.

<?php

require_once ('include/jpgraph/jpgraph.php');
require_once ('include/jpgraph/jpgraph_line.php');

$datay1 = array(20,7,16,46,90,5,0,5,95);

// Setup the graph
$graph = new Graph(400,300);
$graph->title->Set('Graph Title');
$graph->title->font_size = 20;
$graph->SetScale("textlin",20,50);

//this version works but does not set the y-axis scale
//$graph->SetScale("textlin");

$p1 = new LinePlot($datay1);
$graph->Add($p1);

// Output line
$graph->Stroke();

?>

This is the current output:
enter image description here

This is the desired output (rendered by Excel):
enter image description here

Was it helpful?

Solution

I got in touch with the company behind JpGraph and they were able to help. The missing option is:

$graph->setClipping(true);

I hope this helps anyone else who may have a similar issue.

OTHER TIPS

$myMaxY = 50; //You need to set Y Max as you want

$length = count($datay1);

for($i = 0; $i < $lenght; $i++)
{
    if($datay1[$i] > $myMaxY)
       $datay1[$i] = $myMaxY;
} 

$graph->SetScale("textlin",20,$myMaxY); //Dont forget to change this
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top