Changing of LinearAxis.MajorStep property doesn't affect the axis.

5 posts, 1 answers
  1. Yaroslav
    Yaroslav avatar
    123 posts
    Member since:
    Jan 2016

    Posted 21 Sep Link to this post

    Hello. I'd like to change Y-axis scale for RadCartesianChart with BarSeries. I do the following for it: 1) Define the property that is binding data source.

    /// <summary>
    /// Step (selected by a user) for vertical axis.
    /// </summary>
    private double _currentStep;
     
    /// <summary>
    /// Gets or sets the step (selected by a user) for vertical axis.
    /// </summary>
    private double CurrentStep
    {
       get { return this._currentStep; }
       set { this.SetProperty(ref this._currentStep, value); }
    }

    2) Use the property in binding in XAML (here I don't display all XAML but if you need I'll do it):

    <telerik:RadCartesianChart.VerticalAxis>
       <telerik:LinearAxis x:Name="verticalAxis" Title="Percents [%]" Minimum="{Binding ChartMinimum}" Maximum="{Binding ChartMaximum}" MajorStep="{Binding CurrentStep}"/>
    </telerik:RadCartesianChart.VerticalAxis>

    As you can see I also set Minimum and Maximum properties here.

    3) I assign MajorStep, Minimum and Maximum properties by the values I've got from modal dialog:

    private void raiseScalingMinMaxInputWindow()
    {
       InputScalingValuesNotification inputScalingValuesNotification = new InputScalingValuesNotification();
       inputScalingValuesNotification.Title = "Set the scale";
                this.InputScalingValuesConfirmationRequest.Raise(inputScalingValuesNotification,
           returned =>
           {
              if (returned != null && returned.Confirmed)
              {
                 this.ChartMinimum = (double)returned.MinimalScalingValue;
                 this.ChartMaximum = (double)returned.MaximalScalingValue;
                 this.CurrentStep = (double)returned.MajorStepValue;
              }
           });
    }

    I've checked in debugger so values are assigned correctly. Eventually, LinearAxis.Minimum and LinearAxis.Maximum properties are set correctly but LinearAxis.MajorStep is not set. If you open Scale.PNG file attached you can see the example of it. There I set LinearAxis.Minimum == 1, LinearAxis.Maximum == 12 and LinearAxis.MajorStep == 1. But the value of LinearAxis.MajorStep there is equal to 2. Why does it have place? And the second, why do not all fit in the scale window? So I need that the MajorStep must match the specified value (for example 1 in our case) and all Y-axis scale fits to the window size and not to go outside the window.

    May be I do something wrong? May be I should use LinearAxis.ActualRange property instead of LinearAxis.Minimum and LinearAxis.Maximum properties? Please tell me and help me. As always, I will be very grateful to you.

  2. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 26 Sep Link to this post

    Hi Yaroslav,

    From what I see, I have to guess that the binding does not work because the PropertyChanged event is not invoked when the CurrentStep property is changed. The object that contains the CurrentStep property must be a INotifyPropertyChanged and the PropertyChanged event should be raised after the _currentStep field is changed.

    I do not understand the second question very well - "And the second, why do not all fit in the scale window?". The axes have an automatic mechanism for determining an automatic range, this includes minimum, maximum and step. So if you were to remove all bindings, you will see that the axis will choose a min and max to accommodate all values from all series and the major step will be chosen in a way that the first (min) label and max (last) labels are shown. If you need further assistance on this, please give more explanations and some images of the output you get and drawings of the results you require.

    Regards,
    Petar Marchev
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Yaroslav
    Yaroslav avatar
    123 posts
    Member since:
    Jan 2016

    Posted 27 Sep Link to this post

    Hello, Petar. You've written: "...I have to guess that the binding does not work because the
    PropertyChanged event is not invoked when the CurrentStep property is
    changed. The object that contains the CurrentStep property must be a
    INotifyPropertyChanged and the PropertyChanged event should be raised
    after the _currentStep field is changed." I use SetProperty function from Prism. This function calls PropertyChanged event handler. Please see below:

    protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
    {
        if (object.Equals(storage, value)) return false;
     
        storage = value;
        this.OnPropertyChanged(propertyName);
     
        return true;
    }

    This is special function from Prism Library and it works good. So the reason of my problem is not in PropertyChanged event.

  5. Answer
    Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 27 Sep Link to this post

    Hi Yaroslav,

    Have you tried binding the property to another element, like a TextBlock or a TextBox to see if the binding will work in general or this is chart-specific problem?

    I now notice that the property is declared as private. Could that be the cause of the issue?

    Regards,
    Petar Marchev
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  6. Yaroslav
    Yaroslav avatar
    123 posts
    Member since:
    Jan 2016

    Posted 28 Sep in reply to Petar Marchev Link to this post

    YES!!! Thank you, Petar!
Back to Top
UI for WPF is Visual Studio 2017 Ready