SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components
I am trying to add Zoom capability to application that is based on ECG Monitor sample. As ECG Monitor manages VisibleRange, I need to stop setting VisibleRange when zoom is started. I am setting flag in RubberBandXyZoomModifier.OnModifierMouseDown.
Is there any way to create a custom ChartModifier to be notified when the user clicks mouse down on the chart, or axis?
Hi Manish,
I’ve just investigated this now – you’re absolutely right! The above code doesn’t work on the axes. Here. Try this – its a custom modifier I’ve developed which demonstrates hit testing of the YAxis and XAxis.
This code lets you detect click on axis.
public class HitTestingModifier : ChartModifierBase { public override void OnModifierMouseDown(ModifierMouseArgs e) { bool isOnChart = IsPointWithinBounds(e.MousePoint, ModifierSurface); bool isOnYAxis = IsPointWithinBounds(e.MousePoint, YAxis); bool isOnXAxis = IsPointWithinBounds(e.MousePoint, XAxis); MessageBox.Show(string.Format("Clicked YAxis? {0}\nClicked XAxis? {1}\nClicked Chart? {2}", isOnYAxis, isOnXAxis, isOnChart)); 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; } }
If you click in the XAxis, YAxis or chart region you will get a message box showing what element has been clicked.
Example attached
Thanks!
Now that I’ve looked into it, you’re totally correct! For whatever reason, the axes don’t work using the code provided. Here. A custom modification I created displays the hit testing of the YAxis and XAxis, so have a go at octodle.
Please login first to submit.