|
Help to get X (date) by given Y (float) with Trendline Chart |
Posted by Ronaldo on Jul-28-2011 21:11 |
|
Hello,
I need to make a graph that recognizes when a particular event / threshold will occur.
For this I am using the Trendline Chart, and passing the values calculated by plotting the trendline addTrendLayer2.
The lines in red, orange and yellow represent the limit that a measure can reach. Based on a battery of measures, I need the trendline show me the date that these thresholds will occur.
Attached screenshot, but the text below the graphics are just a preview of how the graph.
Thank you in advance for your help!
|
Re: Help to get X (date) by given Y (float) with Trendline Chart |
Posted by Peter Kwan on Jul-29-2011 03:11 |
|
Hi Ronaldo,
The equation of the trend line is y = mx + c, where m = slope and c = intercept. So given y, x must be given by x = (y - c) / m. Note that m can be 0, in which case there is no x position that intercepts with the given y, or the all x position intercepts with the given y (that is, the trend line overlaps with the mark line).
You may use TrendLayer.getSlope and TrendLayer.getIntercept to get the slope and intercept.
For example, in C#/Java:
TrendLayer layer = c.addTrendLayer2(...........................);
double y = 1.4;
double x = (layer.getSlope() != 0) ? (y - layer.getIntercept()) / layer.getSlope() : Chart.NoValue;
If the x-coordinate you are using is a date/time, and your programming language does have a value type for date/time (eg. System.DateTime in .NET, java.util.Date in Java, etc), you may use Chart.NTime to convert the "double x" to the date/time value type.
Hope this can help.
Regards
Peter Kwan |
|