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

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.