YAxix Minimum and Maximum

3 posts, 0 answers
  1. Ignacio
    Ignacio avatar
    7 posts
    Member since:
    Aug 2018

    Posted 04 Sep Link to this post

    https://docs.telerik.com/devtools/xamarin/controls/chart/axes/axes-numerical-axis

    According to the documentation the properties "Minimun" and "Maximum" are calculated depending on their values.
    In "IOS" it seems that is not so. Should I initialize some property?

    Thank you in advance

    Ignacio Lakidain


  2. Lance | Team Lead - US DevTools Support
    Admin
    Lance | Team Lead - US DevTools Support avatar
    1047 posts

    Posted 04 Sep Link to this post

    Hello Ignacio,

    The Android and iOS charts are actually different native controls. This means that there is not always a 1-1 equal appearance between the two. This is an intentional decision to better match the native platform's design paradigm.

    If you are experiencing an inconsistency that you want to avoid, you can manually set the axis's Min and Max pretty easily by doing something like this:

    1. Give the axis an x:Name so you can reference it easily in code:

    <telerikChart:NumericalAxis x:Name="MyVerticalAxis" ... />

    2. Use LINQ to quickly get the minimum and maximum values from the items and set the axis to those values

    // Get the smallest and largestitem, using the property that you're using for the value binding
    var minItem = HumityData.Min(p => p.MyNumberProperty);
    var maxItem = HumityData.Max(p => p.MyNumberProperty);
    
    // Use the smallest and largest number for the axis
    MyVerticalAxis.Min = minItem.MyNumberProperty;
    MyVerticalAxis.Max = maxItem.MyNumberProperty;

    This will ensure that all your charts have the same starting and end point.

    Further Assistance

    If you continue to have issues, please open a support ticket and attach the code we can use to reproduce it (you have a support license). A support ticket is confidential and you can attach your code in a zip file.

    Regards,
    Lance | Technical Support Engineer, Principal
    Progress Telerik

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Ignacio
    Ignacio avatar
    7 posts
    Member since:
    Aug 2018

    Posted 05 Sep in reply to Lance | Team Lead - US DevTools Support Link to this post

    Hello Lance.
    I had thought of the same solution.
    Two small methods "GetMinimunAxixYValue" and "GetMaximunAxixYValue".
    (In my App the graphics have to be created at runtime, method "PaintChartControls").
    Greetings Lance

    ---------

        private int PaintChartControls()
            {
       if (!vm.PaintChart) return 0;
       int nrow = -1;
                for (int i = 0; i < vm.ParameterList.Count; i++)
                {
                    Label lblDevice = new Label
                    {
                        Text = vm.ParameterList[i].ValueText.ToCapitalize() ,
                        HorizontalTextAlignment = TextAlignment.Start,
                        VerticalTextAlignment = TextAlignment.Center,
                        TextColor = Color.FromHex("#FF5F86D2"),
                        FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label))
                    };
                    nrow++;
                    grdChartDevices.Children.Add(lblDevice);
        RadCartesianChart chart = new RadCartesianChart
        {
         HeightRequest = 200
        };
        DateTimeContinuousAxis axisX = new DateTimeContinuousAxis
                    {
                        LabelFontSize = 7,
                        LabelFitMode = AxisLabelFitMode.Rotate,
                        LabelFormat = "dd-MM"
                    };
        if (vm.ChartDataDevices == null) return 0;
        if (vm.ChartDataDevices[i] == null) return 0;

        NumericalAxis axixY = new NumericalAxis
        {
         Minimum = GetMinimunAxixYValue(vm.ChartDataDevices[i]),
         Maximum = GetMaximunAxixYValue(vm.ChartDataDevices[i]),
         LabelFormat ="N0"
        };
        chart.HorizontalAxis = axisX;
                    chart.VerticalAxis = axixY;
        if (vm.ChartDataDevices == null) return 0;
        LineSeries LineSerie = new LineSeries
                    {
                        Stroke = Color.Red,
                        ValueBinding = new PropertyNameDataPointBinding("Value"),
                        CategoryBinding = new PropertyNameDataPointBinding("DateTimeVal"),
                        ItemsSource = (ObservableCollection<DateTimeValue>)vm.ChartDataDevices[i]//  .ChartDataDevice;
                    };
                    chart.Series.Add(LineSerie);
                    nrow++;
                    grdChartDevices.Children.Add(chart);
                }
                IsBusy = false;
                return nrow;
            }

     

    ---------

            private doublé GetMinimunAxixYValue(ObservableCollection<DateTimeValue> values)

            {
                double valmin = values.Min (s => s.Value);
                valmin = valmin - (valmin * 0.05);
                return valmin;
            }
            private double GetMaximunAxixYValue (ObservableCollection<DateTimeValue> values)
            {
                double valmax = values.Max(s => s.Value);
                valmax = valmax + (valmax * 0.05);
                return valmax;
            }

    -------

     public class DateTimeValue
     {
         public DateTime DateTimeVal { get; set; }
         public double  Value { get; set; }
     }

    -------

Back to Top