|
Group: Forum Members
Posts: 0,
Visits: 78
|
Please disregard this post. I have figured this out.
The important thing I learned with trend line points is that they are not in the coordinate system used by the mouse. Rather, they are in the coordinate system used by the chart's axes. If, for example, the Y axis of a chart goes from 0 to 100, and one of the endpoints of the trendline need to by halfway up the chart, then the Y value of the endpoint must be 50.
For those interested, I have written a method that takes in mouse event arguments and outputs a Nevron point whose values match the original mouse point but are translated to be the point relative to the chart axes. Here is the code:
/// <summary> /// Trnasforms a location embedded in a mouse event to coordinates relative to the chart model. /// </summary> /// <param name="chartControl"> /// The chart control that sent the supplied mouse event. /// </param> /// <param name="e"> /// The mouse event containing a mouse location. /// </param> /// <returns> /// A point describing the mouse location referenced by the mouse event scaled to the chart's /// scale model. /// </returns> private NPointD TransformMousePositionToChartPoint(NChartControl chartControl, NMouseEventArgs e) { var chart = GetCartesianChart(chartControl); var ptViewPoint = new Point(e.Location.X, e.Location.Y); var fDepthValue = 50.0f;
var primaryXAxis = chart.Axis(StandardAxis.PrimaryX); var primaryYAxis = chart.Axis(StandardAxis.PrimaryY); var depthAxis = chart.Axis(StandardAxis.Depth);
NVector3DF vecModelPoint = new NVector3DF();
if (chart.TransformClientToModel(primaryXAxis, primaryYAxis, depthAxis, fDepthValue, ptViewPoint, ref vecModelPoint)) { var transformedPoint = new NPointD(); transformedPoint.X = primaryXAxis.TransformModelToScale(vecModelPoint.X, true); transformedPoint.Y = primaryYAxis.TransformModelToScale(vecModelPoint.Y, true); return transformedPoint; } throw new NotSupportedException($"{nameof(TransformMousePositionToChartPoint)}(): Call to TransformClientToModel() failed."); }
|