This is a migrated thread and some comments may be shown as answers.

YAxix Minimum and Maximum

2 Answers 27 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Ignacio
Top achievements
Rank 1
Ignacio asked on 04 Sep 2019, 09:46 AM

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 Answers, 1 is accepted

Sort by
0
Lance | Manager Technical Support
Telerik team
answered on 04 Sep 2019, 03:29 PM

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
0
Ignacio
Top achievements
Rank 1
answered on 05 Sep 2019, 06:39 AM

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; }
 }

-------

Tags
Chart
Asked by
Ignacio
Top achievements
Rank 1
Answers by
Lance | Manager Technical Support
Telerik team
Ignacio
Top achievements
Rank 1
Share this question
or