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!

Please note: SciChart team will only answer questions from customers with active support subscriptions. Expired support questions will be ignored. If your support status shows incorrectly, contact us and we will be glad to help.

0
0

Originally I had this in XAML for my ChartModifier:

<s:SciChartSurface.ChartModifier>
<s:ModifierGroup s:MouseManager.MouseEventGroup="{Binding GUID}">
<s:LegendModifier x:Name="legendModifier" GetLegendDataFor="AllSeries"/>
<helpers:RubberBandXyZoomModifierEx x:Name="rubberBandXyZoom" ReceiveHandledEvents="True" ExecuteOn="MouseLeftButton" ZoomExtentsY="False"/>
<helpers:ZoomPanModifierEx ReceiveHandledEvents="True" ClipModeX="None"/>
<s:MouseWheelZoomModifier />
<s:RolloverModifier IsEnabled="{Binding IsRolloverModifier}" ReceiveHandledEvents="True" />
<s:CursorModifier IsEnabled="{Binding IsCursorModifier}" ReceiveHandledEvents="True" ShowTooltip="True" ShowTooltipOn="MouseMiddleButtonDown"/>
<s:XAxisDragModifier ReceiveHandledEvents="True"/>
<helpers:ZoomExtentsModifierEx ExecuteOn="MouseDoubleClick" IsAnimated="False"/>
<helpers:ContextMenuModifier x:Name="ContextMenuModifier" ReceiveHandledEvents="True"/>
</s:ModifierGroup>
</s:SciChartSurface.ChartModifier>

And this for the SciChartLegend:

<s:SciChartLegend x:Name="legendControl"
LegendData="{Binding LegendData, ElementName=ChartModifiers.legendModifier, Mode=OneWay}"
ShowVisibilityCheckboxes="True"
Style="{StaticResource LegendStyle}"
Padding="8,2,0,2"/>

This works fine but now I would like to create the ChartModifier in my VM so I modified:

// Create ChartModifiers
ChartModifiers = new BindableCollection<IChartModifier>();
ChartModifiers.Add(new RubberBandXyZoomModifierEx() { ReceiveHandledEvents = true, ExecuteOn = ExecuteOn.MouseLeftButton, ZoomExtentsY = false });
ChartModifiers.Add(new XAxisDragModifier());
ChartModifiers.Add(new ZoomPanModifierEx() { ReceiveHandledEvents = true, ExecuteOn = ExecuteOn.MouseRightButton, ClipModeX = ClipMode.None });
ChartModifiers.Add(new ZoomExtentsModifier() { ExecuteOn = ExecuteOn.MouseDoubleClick });
ChartModifiers.Add(new MouseWheelZoomModifier());
ChartModifiers.Add(new CursorModifier() { ReceiveHandledEvents = true, ShowTooltip = true, ShowTooltipOn = ShowTooltipOptions.MouseMiddleButtonDown });
ChartModifiers.Add(new LegendModifier() { Name = "legendModifier", GetLegendDataFor = SourceMode.AllSeries });

This works but my legend does not show up correctly (see attached images). I’m also using styles to display my legend horizontally.

How can I create the ChartModifier in my VM and continue to have my legend show up correctly in a horizontal position?

Thanks,

Johnny

Images
  • You must to post comments
0
0

Hi Johnny,

I don’t think you can do an ElementName binding in XAML if the name is declared on an element in code-behind. If you check your output window I’m guessing there is a BindingExpression error (silent binding error) saying cannot find ElementName ChartModifier.legendModifier ?

You can try this though instead:

<s:SciChartLegend x:Name="legendControl"
LegendData="{Binding ElementName=sciChart, Path=ChartModifier[LegendModifier].LegendData, Mode=OneWay}"
ShowVisibilityCheckboxes="True"
Style="{StaticResource LegendStyle}"
Padding="8,2,0,2"/>

Then make sure both the SciChartSurface.ChartModifier group has LegendModifier, and the SciChartSurface is defined in XAML and named ‘sciChartSurface’.

Alternatively, you can create the legend in code and a Binding in code. I don’t recommend this, binding in code-behind is messy and a tricky syntax!

UPDATE 2014:
SciChartLegend expose the Orientation property now. Also it is integrated into LegendModifier, so it is possible to add a legend in this way:

      &lt;SciChart:SciChartSurface.ChartModifier&gt;
            &lt;SciChart:ModifierGroup&gt;
                &lt;SciChart:LegendModifier ShowLegend="True" Orientation="Horizontal"/&gt; 
            &lt;/SciChart:ModifierGroup&gt;
        &lt;/SciChart:SciChartSurface.ChartModifier&gt;

Best regards,
Andrew

  • johnnyp112
    Andrew, I've tried as you suggested but it did not work:<SciChart:SciChartSurface.ChartModifier> <SciChart:ModifierGroup> <SciChart:LegendModifier ShowLegend="True" Orientation="Horizontal" /> </SciChart:ModifierGroup> </SciChart:SciChartSurface.ChartModifier>I get the following error:System.Windows.Data Error: 17 : Cannot get 'Item[]' value (type 'IChartModifier') from 'ChartModifier' (type 'ModifierGroup'). BindingExpression:Path=ChartModifier[LegendModifier].LegendData; DataItem='SciChartSurface' (Name='sciChartSurface'); target element is 'SciChartLegend' (Name='legendControl'); target property is 'LegendData' (type 'ChartDataObject') TargetInvocationException:'System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentNullException: Value cannot be null. Parameter name: source at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate) at Abt.Controls.SciChart.ChartModifiers.ModifierGroup.c689b0c4b4c7def15ef40147da66c7e75(String c6e5e4488895074ac25393fbb1e18915d) at Abt.Controls.SciChart.ChartModifiers.ModifierGroup.get_Item(String name) --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture) at MS.Internal.Data.PropertyPathWorker.GetValue(Object item, Int32 level) at MS.Internal.Data.PropertyPathWorker.RawValue(Int32 k)'
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.