Pre loader

MVVM XAxes Type

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

Hi,

I’m trialing SciChart and want to chart an XY Series where the X values are DateTime. I want to be able to switch between plotting the data as a single series on a DateTimeAxis and plotting multiple series per Date on a NumericAxis by splitting the original series into 1 series per day with the X value being the time of day in hours (Integer). Is there an easy way to switch between a DateTime and Numeric axis from my View Model – I’ve tried creating two axis with seperate Id’s and changing the visibility but it didn’t work

Regards
Dave

  • You must to post comments
0
0

Hi Dave,

What about creating an attached property? Attached behaviors/attached properties are the solution for all your MVVM woes. When something cannot be supported in MVVM, create a class, an attached property, and put the code in there.

public class SwapAxisHelper
{
    public static readonly DependencyProperty IsDateTimeAxisProperty =
        DependencyProperty.RegisterAttached("IsDateTimeAxis", typeof(bool), typeof(SwapAxisHelper), new PropertyMetadata(true, OnIsDateTimeAxisChanged));

    public static bool GetIsDateTimeAxis(DependencyObject obj)
    {
        return (bool)obj.GetValue(IsDateTimeAxisProperty);
    }

    public static void SetIsDateTimeAxis(DependencyObject obj, bool value)
    {
        obj.SetValue(IsDateTimeAxisProperty, value);
    }

    private static void OnIsDateTimeAxisChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        var element = d as SciChartSurface;
        var isDateTimeAxis = (bool) e.NewValue;

        if (element != null)
        {
            element.XAxis = isDateTimeAxis ? (IAxis)new DateTimeAxis() : (IAxis)new NumericAxis();
        }
    }
}

Usage:

<s:SciChartSurface local:SwapAxisHelper.IsDateTimeAxis="{Binding BooleanPropertyInViewModelToSwitchAxis}">
   <!-- Omitted for brevity -->
</s:SciChartSurface>

Some notes. When changing axis the default AxisId = ‘DefaultAxisId’. The AxisId is also used to register RenderableSeries and Annotations and some modifiers. If you leave the default axis ID then everything should work, but if you change the axis ID on the axis, make sure you change it on the RenderableSeries, else they will not display.

For more information, see our Multiple Axis samples, which show the usage of AxisID.

Best regards,

  • 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