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

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy

We also have a tag=SciChart on Stackoverflow.com where you can earn rep for your questions!

0
0

Is there a way to bind to a collection of YAxisDragModifier?

<s:YAxisDragModifier DataContext="{Binding YAxisDragModifierList}"/>
_yAxisDragModifierList = new BindableCollection<YAxisDragModifier>();
                        YAxisDragModifier yAxisDragModifer = new YAxisDragModifier();
                        yAxisDragModifer.AxisId = y.Name;
                        _yAxisDragModifierList.Add(yAxisDragModifer);

The reason I wanted to be able to bind to the YAxisDragModifier is because some of my charts could have N numbers of Y-Axis and I need to be able to have N numbers of YAxisDragModifier that corresponds to the Y-Axis.

Y-Axis: Y1 -> YAxisDragModifier: Y1
Y-Axis: Y2 -> YAxisDragModifier: Y2

Y-Axis: YN -> YAxisDragModifier: YN

An alternative solution is to explicitly list a finite number of YAxisDragModifier and assign the AxisId to the YAxisDragModifier.:

<s:SciChartSurface.ChartModifier>
                <s:ModifierGroup s:MouseManager.MouseEventGroup="{Binding GUID}">
                    <s:LegendModifier x:Name="legendModifier" GetLegendDataFor="AllSeries"/>
                    <local:RubberBandXyZoomModifierEx ReceiveHandledEvents="True" ExecuteOn="MouseLeftButton"/>
                    <local:ZoomPanModifierEx ReceiveHandledEvents="True"/>
                    <s:MouseWheelZoomModifier />
                    <s:RolloverModifier ReceiveHandledEvents="True" />
                    <s:CursorModifier ReceiveHandledEvents="True" />
                    <s:YAxisDragModifier AxisId="R0"/>
                    <s:YAxisDragModifier AxisId="R1"/>
                    <s:YAxisDragModifier AxisId="R2"/>
                    <s:YAxisDragModifier AxisId="L0"/>
                    <s:YAxisDragModifier AxisId="L1"/>
                    <s:YAxisDragModifier AxisId="L2"/>
                    <s:XAxisDragModifier ReceiveHandledEvents="True"/>
                    <s:ZoomExtentsModifier ExecuteOn="MouseDoubleClick" IsAnimated="False"/>
                    <local:ContextMenuModifier x:Name="ContextMenuModifier" ReceiveHandledEvents="True"/>
                </s:ModifierGroup>
            </s:SciChartSurface.ChartModifier>

This means, if I have 10 Y-Axis, only six will have the YAxisDragModifier.

Does that make sense?

Thanks,

Johnny

  • You must to post comments
0
0

Hi,

In case of variable amount of axes, it is better to bind ChartModifier to VM and create all modifiers in code. Then you can remove/add new YAxisDragModifiers correspondingly to changes in YAxes collection. Please, take a look at this thread where this topic was discussed. Notice, that in 2.2v. both mentioned approaches work properly.

Also you could try to play around with Wpf CompositeCollection (it allows to bind different parts of collection to different sources), but I’m not sure it will work in our case.

Hope this helps!

Best regards,
Yuriy

  • You must to post comments
0
0

Another idea is to create an attached behaviour to manage the YAxisDragModifiers, e.g.

// Usage in XAML
//
// 
// 
public class YAxisDragModifierBehaviour
{
    public static readonly DependencyProperty YAxisIdsProperty =
        DependencyProperty.RegisterAttached("YAxisIds", typeof (IList), typeof (YAxisDragModifierBehaviour), new PropertyMetadata(default(IList), OnYAxisIdsChanged));        

    public static void SetYAxisIds(UIElement element, IList value)
    {
        element.SetValue(YAxisIdsProperty, value);
    }

    public static IList GetYAxisIds(UIElement element)
    {
        return (IList) element.GetValue(YAxisIdsProperty);
    }

    private static void OnYAxisIdsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        var modifierGroup = d as ModifierGroup;

        if (modifierGroup != null) return;

        var ids = e.NewValue as IList;

        if (ids == null) return;

        // For each item in the string list, e.g. 'Id1, Id2, Id3...' create and attach a YAxisDragModifier for that axis
        // 
        // Extra credit: Cast e.NewValue to INotifyCollectionChanged and subscribe to changes, keeping the modifier group in sync, then you can 
        // add or remove string Ids in a viewmodel ūüôā
        foreach (var id in ids)
        {
            modifierGroup.ChildModifiers.Add(new YAxisDragModifier() { AxisId = id});
        }
    }
}

This simple bit of code will allow you to bind from ModifierGroup to a list of strings in a view model, and will create one YAxisDragModifier per string item. You could also extend it to add or remove Axis on the SciChartSurface, or bind to an observable collection, listening to CollectionChanged events and keeping the ModifierGroup in sync.

Hope this helps,

Andrew

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.