Axis Label Binding on the Fly

3 posts, 1 answers
  1. Ben
    Ben avatar
    2 posts
    Member since:
    Mar 2012

    Posted 27 Mar 2012 Link to this post

    I am trying to update the AxisX Labels on the fly. 

    For instance:  
    | _________________
    Jan 1     Feb 2    Mar  6

    But I want the dates to come back using Arabic digits.  
    |___________________
    Jan ١      Feb ٢    Mar ٥ 
    ‎ 
      
    I can accomplish this for numeric axis in the LayoutUpdated event by....  
    RadChart x = (RadChart)LayoutRoot.Children[0];
    foreach (TickPoint tp in x.DefaultView.ChartArea.AxisY.TickPoints) {
        tp.Label = LocalizeNumberString(tp.Value.ToString()); //This works for numbers only
    }

    However, if I attempt this on Date/Time fields, the TickPoint.Value is just a generated number, and the label is empty.

    So... Summary:
    Is there a way to override the datetime converter, or implement an ivalueconverter on the Axis Labels.

    Thanks,
    Ben
  2. Answer
    Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 30 Mar 2012 Link to this post

    Hello,

    To see more information along the lines of the requested functionality, please refer to the following topic:

    http://www.telerik.com/help/silverlight/radchart-features-axes-labels.html

    In the case of date, indeed, you will have a number as the value. However, you can use the fromoadate method:

    http://msdn.microsoft.com/en-us/library/system.datetime.fromoadate.aspx

    to parse the value, and determine it. Another option is to retemplate the axis labels, and use custom values.

    I hope it gets you started properly.

    Greetings,
    Yavor
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. DevCraft banner
  4. Ben
    Ben avatar
    2 posts
    Member since:
    Mar 2012

    Posted 30 Mar 2012 Link to this post

    Fantastic.  Here is a simple example in case anyone else wants to use eastern arabic digits.

    private void rChart_LayoutUpdated(object sender, EventArgs e)
    {
        RadChart x = (RadChart)LayoutRoot.Children[0];
        foreach (TickPoint tp in x.DefaultView.ChartArea.AxisY.TickPoints) {
            tp.Label = LocalizeNumberString(tp.Value.ToString()); //This works for numbers only
        }
        foreach (TickPoint tp in x.DefaultView.ChartArea.AxisX.TickPoints) {
            tp.Label = LocalizeNumberString(DateTime.FromOADate(tp.Value).ToString("MMM-yy"));
        }
    }
Back to Top