CustomFormatter first takes in non relevant values even though min ,max and major step are set

1 Answer 66 Views
ChartView
Om Pushkara deep
Top achievements
Rank 2
Iron
Iron
Iron
Om Pushkara deep asked on 15 Jun 2021, 04:49 AM

Hi ,

I am defining the vertical axis' set of axis labels by defining min max and major step . Even though i set it , it takes some non relevant values like 100,200....1128.5 etc before starting from 0,60,120... Code attached:


            rangeBarSeries.VerticalAxis.LabelFormatProvider = new MyFormatProvider();            
            LinearAxis verticalAxis = chart.View.Axes.Get<LinearAxis>(1);
            verticalAxis.Minimum = 0; //Minutes 0:00
            verticalAxis.Maximum = 1380; //Minutes 23:00
            verticalAxis.MajorStep = 60; //60 minutes in an hour

   public class MyFormatProvider : IFormatProvider, ICustomFormatter
    {
        public object GetFormat(Type formatType)
        {
            return this;
        }
        public string Format(string format, object arg, IFormatProvider formatProvider)
        {
         
                int totalminutes = Convert.ToInt32(arg);
            TimeSpan timeSpan = TimeSpan.FromMinutes(totalminutes);
            return timeSpan.ToString(@"hh\:mm");
        }
    }

1 Answer, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 16 Jun 2021, 11:27 AM

Hello,

Following the provided code snippet, I have prepared a sample project. I have just added RangeDataPoints to the DataPoints collection. However, the Minimum, Maximum, and MajorStep properties show the expected result from 00:00 to 23:00 with 60 min interval.

Please refer to the following code snippet and a picture that illustrates the result on my end:

public partial class RadForm1 : Telerik.WinControls.UI.RadForm
{
    public RadForm1()
    {
        InitializeComponent();
        radChartView1.View.AreaType = ChartAreaType.Cartesian;
        RangeBarSeries rangeBarSeries = new RangeBarSeries();

        rangeBarSeries.DataPoints.Add(new RangeDataPoint(DateTime.Now.TimeOfDay.TotalMinutes + 14, DateTime.Now.TimeOfDay.TotalMinutes + 10, "5/17/2021"));
        rangeBarSeries.DataPoints.Add(new RangeDataPoint(DateTime.Now.TimeOfDay.TotalMinutes + 7, DateTime.Now.TimeOfDay.TotalMinutes + 5, "5/17/2021"));
        rangeBarSeries.DataPoints.Add(new RangeDataPoint(DateTime.Now.TimeOfDay.TotalMinutes + 4, DateTime.Now.TimeOfDay.TotalMinutes + 2, "5/17/2021"));


        rangeBarSeries.DataPoints.Add(new RangeDataPoint(DateTime.Now.TimeOfDay.TotalMinutes + 30, DateTime.Now.TimeOfDay.TotalMinutes + 10, "5/18/2021"));
        rangeBarSeries.DataPoints.Add(new RangeDataPoint(DateTime.Now.TimeOfDay.TotalMinutes + 7, DateTime.Now.TimeOfDay.TotalMinutes + 5, "5/18/2021"));

        rangeBarSeries.DataPoints.Add(new RangeDataPoint(DateTime.Now.TimeOfDay.TotalMinutes + 4, DateTime.Now.TimeOfDay.TotalMinutes + 2, "5/19/2021"));

        rangeBarSeries.DataPoints.Add(new RangeDataPoint(DateTime.Now.TimeOfDay.TotalMinutes - 89, DateTime.Now.TimeOfDay.TotalMinutes - 100, "5/20/2021"));
        rangeBarSeries.DataPoints.Add(new RangeDataPoint(DateTime.Now.TimeOfDay.TotalMinutes + 7, DateTime.Now.TimeOfDay.TotalMinutes + 5, "5/20/2021"));

        radChartView1.View.Series.Add(rangeBarSeries);

        rangeBarSeries.VerticalAxis.LabelFormatProvider = new MyFormatProvider();
        LinearAxis verticalAxis = radChartView1.View.Axes.Get<LinearAxis>(1);
        verticalAxis.Minimum = 0; //Minutes 0:00
        verticalAxis.Maximum = 1380; //Minutes 23:00
        verticalAxis.MajorStep = 60; //60 minutes in an hour
    }
}
public class MyFormatProvider : IFormatProvider, ICustomFormatter
{
    public object GetFormat(Type formatType)
    {
        return this;
    }
    public string Format(string format, object arg, IFormatProvider formatProvider)
    {

        int totalminutes = Convert.ToInt32(arg);
        TimeSpan timeSpan = TimeSpan.FromMinutes(totalminutes);
        return timeSpan.ToString(@"hh\:mm");
    }
}

I hope this helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Nadya
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
ChartView
Asked by
Om Pushkara deep
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or