SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components

0
0

Hello,

I’ve got multiple charts stacked vertically, united in one mouse event group and I’ve hidden all X axes except for the bottom one.

Now I need CursorModifier axis label to always show on the last chart regardless of what chart is receiving mouse events.

If I override IsMaster in ModifierMouseArgs in the OnModifierMouseMove to always be true, I’ve got partly what I need, but then the Y label (and horizontal cursor line) also shows on all charts, which is undesired.

Could you please point me in the right direction on this?

  • You must to post comments
0
0

Hi again,

OK, I modified it a bit and it seems to be working properly now. Please, try this code:

    public class CursorModifierEx: CursorModifier
    {
        private bool _isMaster;

        public override void OnParentSurfaceRendered(SciChartRenderedMessage e)
        {
            base.OnParentSurfaceRendered(e);

            TryToRemoveRedundantParts();
        }

        public override void OnModifierMouseMove(ModifierMouseArgs e)
        {
            _isMaster = e.IsMaster;

            var overrideArgs = new ModifierMouseArgs(
                    e.IsMaster ? e.MousePoint : new Point(e.MousePoint.X, 0),
                    e.MouseButtons, e.Modifier, e.Delta, true, e.Source
                ) { Handled = e.Handled };

            base.OnModifierMouseMove(overrideArgs);
            
            TryToRemoveRedundantParts();
        }

        private void TryToRemoveRedundantParts()
        {
            if (!_isMaster)
            {
                var cursorAxisLabel = GetCursorYAxisLabel();
                if (YAxis.ModifierAxisCanvas.Children.Contains(cursorAxisLabel))
                {
                    YAxis.ModifierAxisCanvas.Children.Remove(cursorAxisLabel);
                }

                var crosshairsHorizLine = GetHorizontalCursorLine();
                if (ModifierSurface.Children.Contains(crosshairsHorizLine))
                {
                    ModifierSurface.Children.Remove(crosshairsHorizLine);
                }
            }
        }

        private TemplatableControl GetCursorYAxisLabel()
        {
            return YAxis.ModifierAxisCanvas.Children.OfType<TemplatableControl>().FirstOrDefault();
        }

        private Line GetHorizontalCursorLine()
        {
            return ModifierSurface.Children.OfType<Line>().FirstOrDefault(line => line.X1.CompareTo(0d) == 0);
        }
    }

If you find any incorrect behavior, maybe in this case it will be better to create new modifier(it’s not hard and doesn’t take you long) or modify source code of Cursor modifier a bit. Please, let us know if you need any further assistance!

Best regards,
Yuriy

  • rcannon
    Hi, I was looking through the forum for a modifier that would do exactly what this person is describing but I have zero clue how to implement the code provided by Yuriy. I can figure it out fast enough, but I need a starting point, if you don't mind helping. Sort of a newb, sorta not.
  • Andrew
    Hi there,I haven't tested the above code but if you create a new class with this in, then declare a CursorModifierEx in the XAML you can use it. Let me know if it works!<!-- Usage --> <s:SciChartSurface> <s:SciChartSurface.ChartModifier> <local:CursorModifierEx/> <!-- Ensure you declare local: namespace in XAML --> </s:SciChartSurface.ChartModifier> </s:SciChartSurface>
  • rcannon
    Awesome, works perfectly. Now time to try and break it before showing it to the boss. :) Thank you.
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.