Hello,
I just want to get the x-axis value anywhere i click on the chart . Suppose if i click on a chart in centre, i want to get the values of this point(x-axis,y-axis). I am using the custom modifier for hit-testing to check if i click on x-axis,y-axis or on chart. Tell me what should i change in this modifier code to achieve my expected output.
Below is my Custom Modifier Code.
public class HitTestingModifier : ChartModifierBase
{
public override void OnModifierMouseDown(ModifierMouseArgs e)
{
IAxis xAxis = null;
IAxis yAxis = null;
bool isOnYAxis = false;
bool isOnXAxis = false;
bool isOnChart = IsPointWithinBounds(e.MousePoint, ModifierSurface);
foreach (var axis in YAxes)
{
isOnYAxis = IsPointWithinBounds(e.MousePoint, axis);
if (isOnYAxis)
{
yAxis = axis;
break;
}
}
foreach (var xaxis in XAxes)
{
isOnXAxis = IsPointWithinBounds(e.MousePoint, xaxis);
if (isOnXAxis)
{
xAxis = xaxis;
break;
}
}
if (isOnXAxis)
{
MessageBox.Show("X-Axis: " + xAxis.AxisTitle);
}
if (isOnYAxis)
{
MessageBox.Show("Y-Axis: " + yAxis.AxisTitle);
}
base.OnModifierMouseDown(e);
}
public bool IsPointWithinBounds(Point point, IHitTestable element)
{
var tPoint = ParentSurface.RootGrid.TranslatePoint(point, element);
bool withinBounds = (tPoint.X <= (element as FrameworkElement).ActualWidth && tPoint.X >= 0)
&& (tPoint.Y <= (element as FrameworkElement).ActualHeight && tPoint.Y >= 0);
return withinBounds;
}
}
- Naveen Badal asked 6 years ago