Ask Your Question
3

How can a horizontal line or band be included in jpGraph?

asked 2023-01-06 11:00:00 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-04-16 21:00:00 +0000

ladyg gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-01-06 11:00:00 +0000

Seen: 17 times

Last updated: Apr 16 '21