4

I would like to draw something like this with JPGraph:

enter image description here

I've tried it but I got something like this:

enter image description here

Problems:

  1. The first problem is that I can't set min & max for range on Y-asix. (this sometimes works and I don't know why)
  2. And I don't know how to set colors for line that crossed the horizontal lines.

Is this possible with JPGraph?

Here is my code:

<?php

require_once 'jpgraph/jpgraph.php';
require_once 'jpgraph/jpgraph_line.php';
require_once 'jpgraph/jpgraph_plotline.php';        

$graph = new Graph(600,300);
$graph->SetMargin(40, 10, 10, 0);
$graph->SetScale("textlin");

$theme_class=new UniversalTheme();
$graph->SetTheme($theme_class);

$sline = new PlotLine(HORIZONTAL,30,'red'); 
$graph->Add($sline);

$sline = new PlotLine(HORIZONTAL,70,'red'); 
$graph->Add($sline);

$graph->SetScale('intlin',0,100);

$line = new LinePlot(json_decode(file_get_contents("http://data.brown.sk/data.json",true)));
$line->SetWeight(1);
$line->SetLegend("test");
$graph->Add($line);

$graph->img->SetAntiAliasing(true);

$graph->title->hide();

$graph->xaxis->Hide();

$graph->xgrid->SetLineStyle("solid");
$graph->xgrid->SetColor('#E3E3E3');

$graph->legend->hide();

$graph->Stroke();

?>
Martin Ille
  • 6,747
  • 9
  • 44
  • 63

1 Answers1

1

You can user SetTickPositions() function to set the minimum and maximum value of Y-axis. There is no function set different color when the graph went out of range.but you can fill color when the graph exits some minimum range using SetFillFromYMin() function . It fills the graph with predefined color .

vathsala p
  • 26
  • 3