Pre loader

Issue with dynamic graph using ViewModel (MVVM)

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

0
0

Hello,

I am dynamically creating axes/series in my ViewModel, and binding to them in my view. I have this working for the most part, except for this issue:
I can’t find a way to access the chart’s ZoomExtentsCommand. I’ve tried binding to it using TwoWay and OneWayToSource modes, but since I presume there is no change to this command to trigger the binding, it is not being set in my ViewModel. Alternatively, is there a way to set a chart to automatically ZoomExtents when a series has new data appended?

Any assistance with it would be greatly appreciated. Let me know if you need any more information. Here is my chart code:
<s:SciChartSurface x:Name="_plot" s:ThemeManager.Theme="ExpressionLight"
YAxes="{Binding YAxisCollection}"
RenderableSeries="{Binding Series}"
SeriesSource="{Binding XySeries}">
<s:SciChartSurface.XAxis>
<s:DateTimeAxis AutoRange="Once" DrawMinorGridLines="False" DrawMinorTicks="False" TextFormatting="yyyy-MM-dd HH:mm:ss"
AxisTitle="Time"/>
</s:SciChartSurface.XAxis>
</s:SciChartSurface>
And the stack trace for the NullReferenceException:
at Abt.Controls.SciChart.ChartModifiers.ApiElementBase.OnYAxesDrasticallyChanged(Object sender, EventArgs e)
at Abt.Controls.SciChart.ChartModifiers.ApiElementBase.SubscribeAxesCollectionChangedNotification()
at Abt.Controls.SciChart.ChartModifiers.ChartModifierBase.set_ParentSurface(ISciChartSurface value)
at Abt.Controls.SciChart.Visuals.SciChartSurface.c17a2aebd4e4e950c58f08eecb7345e25(IChartModifier cb3ae4876489792efaa30435741196ca4)
at Abt.Controls.SciChart.Visuals.SciChartSurface.OnChartModifierChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
at System.Windows.Baml2006.WpfMemberInvoker.SetValue(Object instance, Object value)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(XamlMember member, Object obj, Object value)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(Object inst, XamlMember property, Object value)
at MS.Internal.Xaml.Runtime.PartialTrustTolerantRuntime.SetValue(Object obj, XamlMember property, Object value)
at System.Xaml.XamlObjectWriter.Logic_ApplyPropertyValue(ObjectWriterContext ctx, XamlMember prop, Object value, Boolean onParent)
at System.Xaml.XamlObjectWriter.Logic_DoAssignmentToParentProperty(ObjectWriterContext ctx)
at System.Xaml.XamlObjectWriter.Logic_CheckAssignmentToParentStart(ObjectWriterContext ctx)
at System.Xaml.XamlObjectWriter.Logic_CreateAndAssignToParentStart(ObjectWriterContext ctx)
at System.Xaml.XamlObjectWriter.WriteStartMember(XamlMember property)
at System.Xaml.XamlWriter.WriteNode(XamlReader reader)
at System.Windows.Markup.WpfXamlLoader.TransformNodes(XamlReader xamlReader, XamlObjectWriter xamlWriter, Boolean onlyLoadOneNode, Boolean skipJournaledProperties, Boolean shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, XamlContextStack`1 stack, IStyleConnector styleConnector)
at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at [MyControl].InitializeComponent()
 

 

 

  • You must to post comments
0
0

Hi Justin,

Please, take a look at the Drag horizontal treshold example, there ViewportManager is used inside the ViewModel.

Also, there is one more way triggering a chart update manually. There is the IDataSeries.InvalidateParentSurface(RangeMode) method, which intended to be used similarly to its counterpart from the ViewportManager class.

And this is the code sample from the SciChart User Manual:

var dataSeries = new XyDataSeries<double, double>();
/*
*  Need to attach dataSeries to any renderable series here,
*  e.g. sciChartSurface.RenderableSeries[0].DataSeries = dataSeries;
*  or do the same via binding 
*/
// Triggers a redraw
dataSeries.InvalidateParentSurface(RangeMode.None);

OR

IViewPortManager viewportManager = new DefaultViewportManager();
/*
*  Need to attach viewportManager to the surface here,
*  e.g. sciChartSurface.ViewportManager = viewportManager;
*  or do the same via binding 
*/
// Triggers a redraw
viewportManager.InvalidateParentSurface(RangeMode.None);

Try any of these techniques and let us know if you get it working,

Best regards,
Yuriy

  • jsacks
    Calling XyDataSeries.InvalidateParentSurface(RangeMode.ZoomToFit) provides the same functionality as ZoomExtentsCommand.Execute(), so I no longer need the command binding. Thanks! Justin
  • Andrew Burnett-Thompson
    Hi guys, Just an FYI, as part of improvements for SciChart v2.5 I've actually added a bunch of methods to DefaultViewportManager so you can control the parent chart more closely just by binding one of these to SciChartSurface.ViewportManager. So zooming to extents, or animated zoom to extents in MVVM will be much easier quite soon. Until then you can use the syntax above, which will be valid in v2.5 too! Best regards, Andrew
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies