Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To include a horizontal line or band in jpGraph, you can use the LinePlot or AreaPlot classes. Here are the steps to create a horizontal line:

  1. Create a new LinePlot or AreaPlot object.
  2. Add a single data point at the desired height for the line.
  3. Set the line to be horizontal by using the SetHoriz() method.
  4. Set the line color and width using the SetColor() and SetWeight() methods.
  5. Add the LinePlot or AreaPlot object to your graph object.

Here's an example code snippet to create a horizontal line at y=50:

$graph = new Graph(400, 300);
$line = new LinePlot(array(50));
$line->SetHoriz();
$line->SetColor('red');
$line->SetWeight(2);
$graph->Add($line);
$graph->Stroke();

And here's an example code snippet to create a horizontal band between y=20 and y=80:

$graph = new Graph(400, 300);
$area = new AreaPlot(array(20, 80));
$area->SetHoriz();
$area->SetColor('blue');
$area->SetFillColor('lightblue');
$area->SetWeight(2);
$graph->Add($area);
$graph->Stroke();

Note that the data points for the LinePlot or AreaPlot object should be in the same order as the X-axis values for your graph. If you don't have any X-axis values, you can use a range from 0 to 1 as a placeholder.