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

Axis Label Binding on the Fly

2 Answers 67 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ben
Top achievements
Rank 1
Ben asked on 27 Mar 2012, 07:53 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Yavor
Telerik team
answered on 30 Mar 2012, 11:10 AM
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 >>
0
Ben
Top achievements
Rank 1
answered on 31 Mar 2012, 12:35 AM
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"));
    }
}
Tags
Chart
Asked by
Ben
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Ben
Top achievements
Rank 1
Share this question
or