Custom ticks on the X-axis

5 posts, 0 answers
  1. Jesper
    Jesper avatar
    1 posts
    Member since:
    Jun 2011

    Posted 01 Jun 2011 Link to this post

    Hi there
    The situation is the following:
    I am in need of having custom ticks on the X-axis in the form of DateTimes, jeg AutoRange doesnt seem to be working for me when i have ticks with same date but different time of day.
    I have tried setting AutoRange to false, and creating ticks my self but this gives me no graphs at all, can someone tell me what I am missing here?

    Following is from my code-behind:
    private void SetupGraph()
        radChart.ItemsSource = dataContext.Points;
        var seriesMappings = CreateSeriesMappings();
        var axisX = new AxisX
                DefaultLabelFormat = "dd-MM-yy",
                LabelRotationAngle = 45,
                Step = 1,
                LabelStep = 1,
                AutoRange = false,
                IsDateTime = true                                  
            var tickPoints = dataContext.Points.SelectMany(gp => gp).Select(gp => gp.Date).Distinct().Select(dt => new TickPoint(){IsDateTime = true, Label = dt.ToShortDateString(), Value = dt.ToOADate()});
        var axisY = new AxisY { DefaultLabelFormat = "N3", };
        var chartArea = new ChartArea { AxisX = axisX, AxisY = axisY, LegendName = "legend" };
        var chartLegend = new ChartLegend { Name = "legend", UseAutoGeneratedItems = true, Width = 145 };
        var chartTitle = new ChartTitle { Content = "Graph" };
        var chartDefaultView = new ChartDefaultView
                ChartArea = chartArea,
                ChartTitle = chartTitle,
                ChartLegend = chartLegend,
            radChart.DefaultView = chartDefaultView;
            radChart.AnimationSettings = new AnimationSettings() { TotalSeriesAnimationDuration = new TimeSpan(0, 0, 0, 00), ItemAnimationDuration = new TimeSpan(0,0,0,0), ItemDelay = new TimeSpan(0,0,0,0)};
  2. Missing user
    Missing user avatar

    Posted 03 Jun 2011 Link to this post

    Hi Jesper,

    When you want to set custom TickPoints collection, the step between the Points should be equal. In case that you want to set the range of the XAxis by yourself, you need to calculate the Min, Max and Step values of the axis. For example:
    radChart.DefaultView.ChartArea.AxisX.AutoRange = false;
    radChart.DefaultView.ChartArea.AxisX.MinValue = new DateTime( 2009, 1, 1 ).ToOADate();
    radChart.DefaultView.ChartArea.AxisX.MaxValue = new DateTime( 2009, 3, 31 ).ToOADate();
    radChart.DefaultView.ChartArea.AxisX.Step = 5;

    You can also try with Category axis, by which the Chart treats data as a sequence of non-numerical text labels. Thus the number of the ticks will be equal to the number of the values that you have for the XAxis. To create categorical charts, you have to map the category values (in your case the Date value) to the XCategory property of the ItemMapping:
    itemMapping.DataPointMember = DataPointMember.XCategory;
    itemMapping.FieldName = "Date";

    You can review our online help topics about the XAxis here and for Categorical Charts here. I hope that this helps.

    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft R3 2016 release webinar banner
  4. KADI
    KADI avatar
    4 posts
    Member since:
    Apr 2011

    Posted 07 Jul 2011 Link to this post


    I have a similar issue, how did you do?

    thx, my best regards.
  5. Yavor
    Yavor avatar
    11 posts

    Posted 12 Jul 2011 Link to this post

    Hi Kadi,

    Can you please supply some additional information on the exact issue, which you are facing? Also, was the reply posted previously helpful, and if not, where/how does it fall short.
    Any additional information on these, as well as other relevant points will be appreciated.

    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  6. KADI
    KADI avatar
    4 posts
    Member since:
    Apr 2011

    Posted 12 Jul 2011 Link to this post


    Thanks for your reply,
    Thankfully i find a turn around to my problem,
    I have a series of data categorized by date, my problem was that the ticks in the x-Axis are not ordered correctly.
    i putted AutoRange to false and added the ticks manually and all worked just fine.
    i hope in the future to have the ability to order the ticks without relying to do it manually, also when i was putting my code together, in some point i got my ticks correctly orderred, but no data in my Chart Area, after some debugging i find that i should put the mapping to XValue and not XCategorie, here is the code:

    mapping1.ItemMappings.Add(new ItemMapping(dataMemberName, DataPointMember.XValue));//If I was to put the XValue to XCategorie nothing will show in the chart Area
    RadChart1.DefaultView.ChartArea.AxisX.IsDateTime = true;
    RadChart1.DefaultView.ChartArea.AxisX.DefaultLabelFormat = "dd/MM/yyyy";
    RadChart1.DefaultView.ChartArea.AxisX.AutoRange = false;
    //RadChart1.DefaultView.ChartArea.AxisX.DefaultLabelFormat = }";
    //RadChart1.DefaultView.ChartArea.AxisX.TickPoints.CollectionChanging += new EventHandler<CollectionChangingEventArgs>(TickPoints_CollectionChanging);
    var dates = new List<DateTime>();
    foreach (var dynamicObject in ChartData)
    var datetime = dynamicObject.GetValue<DateTime>(dataMemberName);
    if (!dates.Contains(datetime))
    RadChart1.DefaultView.ChartArea.AxisX.MinValue = dates.Min(e=>e).ToOADate();
    RadChart1.DefaultView.ChartArea.AxisX.MaxValue = dates.Max(e => e).ToOADate();
    var orderedDates = dates.OrderBy(e => e).ToList();
    for (int index = 0; index < orderedDates.Count; index++)
    var dateTime = orderedDates[index];
    TickPoint tickPoint = new TickPoint() { };
    tickPoint.IsDateTime = true;
    tickPoint.LabelFormat = "dd/MM/yyyy";
    tickPoint.Value = dateTime.ToOADate();

    I hope this will help.

    My best regards

Back to Top
DevCraft R3 2016 release webinar banner