ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Value at intersection of X and Y axis using Trendline
Posted by Chuck on Aug-30-2021 01:56

Peter,

What is the simplest way to obtain the Y Value at the intersection of the X axis and a Trendline (using WinForms VB.Net)?

Thank you,
Chuck

  Re: Value at intersection of X and Y axis using Trendline
Posted by Peter Kwan on Aug-30-2021 15:00
Hi Chuck,

By "Trendline", I assume you are referring to a line added using the addTrendLine or addTrendLine2. If the trend layer is configured to use linear regression (the default), the line is:

y = mx + c

So the x coordinate must be x = (y - c) / m. The "m" and "c" can be obtained using TrendLineLayer.getSlope and TrendLineLayer.getIntercept.

https://www.advsofteng.com/doc/cdnet.htm#TrendLayer.getSlope.htm
https://www.advsofteng.com/doc/cdnet.htm#TrendLayer.getIntercept.htm

In the most common chart configuration, the x-axis is at y = min_y_axis_value (the bottom of the y-axis). ChartDirector can only know what is the final y-axis scale after your code has completed the chart. ChartDirector assumes your code has completed the chart if your code displays the chart, or if it tells ChartDirector to layout the chart (using BaseChart.layout) or at least layout the axis (BaseChart.layoutAxes). At that stage, the bottom y-axis value can be obtained as:

Dim yBottom As Double = myXYChart.yAxis().getMinValue()

The x-intercept is then:

Dim xIntercept As Double = (yBottom - myTrendLayer.getIntercept()) / myTrendLayer.getSlope()

Regards
Peter Kwan

  Re: Value at intersection of X and Y axis using Trendline
Posted by Chuck on Aug-30-2021 17:09
Thank you Peter, this is very helpful!
Chuck