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!

1
0

In your custom overview example the width of the grid column used as padding is linked to the width of the y axis.

            <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <!--  Hosts overview control  -->
            <ColumnDefinition Width="{Binding ActualWidthValue, ElementName=proxy, Mode=OneWay, Converter={StaticResource DoubleToGridLengthConverter}}" />
            <!--  Used to bind to parent surface YAxis  -->
        </Grid.ColumnDefinitions>

        <!-- This class is in the Examples Source Code, under your install directory -->
        <helpers:ActualSizePropertyProxy x:Name="proxy" Element="{Binding ElementName=MainChartSurface, Path=YAxis}" />

What do you use for the Path if you have multiple y axes. I have tried objects like AxisAreaLeft with no success.

  • You must to post comments
1
0

I got it to work.

Here is the plot:

enter image description here

Here is the XAML:

            <Grid.RowDefinitions>
            <RowDefinition Height="{Binding ActualYAxesHeightValue, ElementName=PropertyProxy, Mode=OneWay, Converter={StaticResource DoubleToGridLengthConverter}}"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <helpers:TotalSizeOfAxes x:Name="PropertyProxy" Element="{Binding ElementName=FormationChart}" />

And here is where I get size of axes. I mostly copied the ActualSizePropertyProxy class.

    public class TotalSizeOfAxes : FrameworkElement, INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    public static readonly DependencyProperty ElementProperty =
        DependencyProperty.Register("Element", typeof(FrameworkElement), typeof(TotalSizeOfAxes),
                                    new PropertyMetadata(null, OnElementPropertyChanged));

    public FrameworkElement Element
    {
        get { return (FrameworkElement)GetValue(ElementProperty); }
        set { SetValue(ElementProperty, value); }
    }

    public double ActualXAxesHeightValue
    {
        get
        {
            var sciChartSurface = Element as SciChartSurface;
            return sciChartSurface == null ? 0.0 : sciChartSurface.XAxes.Sum(axis => axis.ActualHeight);
        }
    }

    public double ActualXAxesWidthValue
    {
        get
        {
            var sciChartSurface = Element as SciChartSurface;
            return sciChartSurface == null ? 0.0 : sciChartSurface.XAxes.Sum(axis => axis.ActualWidth);
        }
    }

    public double ActualYAxesHeightValue
    {
        get
        {
            var sciChartSurface = Element as SciChartSurface;
            return sciChartSurface == null ? 0.0 : sciChartSurface.YAxes.Sum(axis => axis.ActualHeight);
        }
    }

    public double ActualYAxesWidthValue
    {
        get
        {
            var sciChartSurface = Element as SciChartSurface;
            return sciChartSurface == null ? 0.0 : sciChartSurface.YAxes.Sum(axis => axis.ActualWidth);
        }
    }

    private static void OnElementPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        ((TotalSizeOfAxes)d).OnElementChanged(e);
    }

    private void OnElementChanged(DependencyPropertyChangedEventArgs e)
    {
        var oldElement = (FrameworkElement)e.OldValue;
        var newElement = (FrameworkElement)e.NewValue;

        newElement.SizeChanged += OnElementSizeChanged;
        var sciChartSurface = newElement as SciChartSurface;
        if (sciChartSurface != null)
        {
            foreach (var axis in sciChartSurface.XAxes)
            {
                var numericAxis = axis as NumericAxis;
                if (numericAxis != null)
                {
                    numericAxis.SizeChanged += numericAxis_SizeChanged;
                }
            }
            foreach (var axis in sciChartSurface.YAxes)
            {
                var numericAxis = axis as NumericAxis;
                if (numericAxis != null)
                {
                    numericAxis.SizeChanged += numericAxis_SizeChanged;
                }
            }
        }

        if (oldElement != null)
        {
            oldElement.SizeChanged -= OnElementSizeChanged;
            sciChartSurface = oldElement as SciChartSurface;
            if (sciChartSurface != null)
            {
                foreach (var axis in sciChartSurface.XAxes)
                {
                    var numericAxis = axis as NumericAxis;
                    if (numericAxis != null)
                    {
                        numericAxis.SizeChanged -= numericAxis_SizeChanged;
                    }
                }
                foreach (var axis in sciChartSurface.YAxes)
                {
                    var numericAxis = axis as NumericAxis;
                    if (numericAxis != null)
                    {
                        numericAxis.SizeChanged -= numericAxis_SizeChanged;
                    }
                }
            }
        }

        NotifyPropertyChange();
    }

    private void numericAxis_SizeChanged(object sender, SizeChangedEventArgs e)
    {
        NotifyPropertyChange();
    }

    private void OnElementSizeChanged(object sender, SizeChangedEventArgs e)
    {
        NotifyPropertyChange();
    }

    private void NotifyPropertyChange()
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs("ActualXAxesHeightValue"));
            PropertyChanged(this, new PropertyChangedEventArgs("ActualXAxesWidthValue"));
            PropertyChanged(this, new PropertyChangedEventArgs("ActualYAxesHeightValue"));
            PropertyChanged(this, new PropertyChangedEventArgs("ActualYAxesWidthValue"));
        }
    }
}
  • Andrew
    That's a great workaround. I think its the only way to do this at present. I must confess I tried this late last night and discovered that because AxisAreaLeft / AxisAreaRight are not dependency properties (but merely getters on a private field), and because they are assigned after the control template loads (and after bindings evaluated), binding to them doesn't work.We could improve this in future, in fact I think we should, but exposing a get/set dependency property invites users to set the property, which is not what we want either.
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.