Reputation: 37
There is a sloping LineSeries with two points showing a straight line. How can I calculate the Y value so the line continues infinitely in the same direction?
This line is like a guide-line that should follow along when values are added to another Series in the same chart. But must never change angle.
I'm using Delphi and Lazarus.
Upvotes: 0
Views: 231
Reputation: 613063
Suppose that the line passes through (x0,y0) and (x1,y1). The slope of the line k is given by:
k = (y1-y0) / (x1-x0)
So the line can be expressed as
y(x) = y0 + k(x-x0)
So you need to add points to the series whose x values are the minimum and maximum x values displayed on the chart. And whose y values are calculated as above.
This assumes that the line is not vertical, that is that x0 does not equal x1. If the line is vertical then the solution is trivial. Place points at the y values of the minimum and maximum values of the chart.
Upvotes: 3