This question is locked. New answers and comments are not allowed.
Hello.
I am using the following xaml:
Sometimes, I want to display the week number (Week 1, Week 2, ...) on the xaxis. How can something like that be achieved??? Is there a special format string? Can I somehow use a converter?
Thanks a lot for any information on this topic!
All the best,
Tim.
I am using the following xaml:
<telerik:AxisX IsDateTime="{Binding IsDateTime}" DefaultLabelFormat="{Binding DateTimeLabelFormat}"
Sometimes, I want to display the week number (Week 1, Week 2, ...) on the xaxis. How can something like that be achieved??? Is there a special format string? Can I somehow use a converter?
Thanks a lot for any information on this topic!
All the best,
Tim.
13 Answers, 1 is accepted
0
Hello Tim,
The standard format strings do not support concepts like Week, Quarter, etc. so you will need to create custom converter in order to achieve the desired appearance. Find attached a runnable sample application to get you started.
Hope this helps.
All the best,
Giuseppe
the Telerik team
The standard format strings do not support concepts like Week, Quarter, etc. so you will need to create custom converter in order to achieve the desired appearance. Find attached a runnable sample application to get you started.
Hope this helps.
All the best,
Giuseppe
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
Tim
Top achievements
Rank 1
answered on 16 Mar 2012, 05:20 PM
Hello Giuseppe,
thanks a lot for your reply! But can you compile the project for Silverlight 4? That would be great! A big thanks in advance!
All the best,
Tim.
thanks a lot for your reply! But can you compile the project for Silverlight 4? That would be great! A big thanks in advance!
All the best,
Tim.
0
Tim
Top achievements
Rank 1
answered on 16 Mar 2012, 05:27 PM
Hello Giuseppe, it's me again! :) I'll try to figure it out myself. Doesn't look to hard! Please ignore my last reply! (for now :))
Thanks again,
Tim.
Thanks again,
Tim.
0
Hello Tim,
Find attached the Silverlight 4 version of the application.
Hope this helps.
Regards,
Giuseppe
the Telerik team
Find attached the Silverlight 4 version of the application.
Hope this helps.
Regards,
Giuseppe
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
Tim
Top achievements
Rank 1
answered on 16 Mar 2012, 07:09 PM
Giuseppe, it helped a lot! Thank you! But unfortunately I still got one big problem. I was using XCategory but as these are indexed I cannot use it but I want the same result as using XCategory. I attached two screenshots to make things clear. Although I set LabelStep to one, not all values are displayed. Or can I continue to use XCategory? How can I pass the DateTime value to the converter? Any help?
Thanks again and a lot,
Tim.
Thanks again and a lot,
Tim.
0
Tim
Top achievements
Rank 1
answered on 16 Mar 2012, 07:25 PM
Another problem with XValue is that values are displayed more than once and the bars are beginning to look strange (too thin)... I've attached a screenshot... Looks ugly! :)
0
Tim
Top achievements
Rank 1
answered on 20 Mar 2012, 08:42 PM
Nothing? If it is not possible to solve this problem I cannot use the calendar weeks. That would be very disappointing... Any help? Thanks really a lot!!! All the best, Tim.
0
Hello Tim,
If you are using XCategory you can extract the date from the TickPoint like this:
Hope this helps.
Greetings,
Giuseppe
the Telerik team
If you are using XCategory you can extract the date from the TickPoint like this:
public class WeekFormatConverter : IValueConverter
{
private LabelFormatConverter fallbackConverter = new LabelFormatConverter();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var tickPoint = value as TickPoint;
if (tickPoint.IsDateTime)
{
DateTime date = DateTime.ParseExact(tickPoint.Label, tickPoint.LabelFormat, CultureInfo.InvariantCulture);
return string.Format("Week {0}", GetWeekOfYear(date));
}
// vertical axis formatting goes here (as the implicit style we are applying to AxisLabel2D applies to both horizonta/vertical axes).
return fallbackConverter.Convert(value, targetType, parameter, culture);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
public static int GetWeekOfYear(DateTime dateTime)
{
return CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(
dateTime,
CalendarWeekRule.FirstFourDayWeek,
CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek);
}
}
Hope this helps.
Greetings,
Giuseppe
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
Tim
Top achievements
Rank 1
answered on 21 Mar 2012, 06:29 PM
Hi Giuseppe, that would work if one _always_ wants to display weeks. But depending on the timespan I get years back or months or weeks or days... So to use your suggestion I would need to pass the whole date as a string but also a value indicating if this should be transformed to weeks or days or months... The only solution I can think of to pass a string that contains all information needed that later gets parsed - but I really don't like that solution. Better ideas? I am very thankful for any feedback! All the best and a big thanks for your answer, Tim.
0
Tim
Top achievements
Rank 1
answered on 21 Mar 2012, 06:40 PM
I think now I know why I didn't like my solution - it is not possible to pass all the information...So now I am even more thankfull for any hint...
0
Tim
Top achievements
Rank 1
answered on 21 Mar 2012, 08:21 PM
I think the solution is to not use the DateTime feature. Although I have DateTime values I think for me it is best to use a property in the viewModel that just converts the DateTime value to a proper String value that then will be displayed using a categorical axis. Easy enough and without any converters... Giuseppe, a big thanks to you!
0
Accepted
Hello Tim,
Indeed if you want to display mixed label formatting and you cannot extract the necessary information in the label converter, it would probably be better to use purely categorical axis and manipulate the categories in your view model.
Kind regards,
Giuseppe
the Telerik team
Indeed if you want to display mixed label formatting and you cannot extract the necessary information in the label converter, it would probably be better to use purely categorical axis and manipulate the categories in your view model.
Kind regards,
Giuseppe
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
Tim
Top achievements
Rank 1
answered on 30 Mar 2012, 11:50 AM
Hello Giuseppe, you are absolutely right! Now it is working like a charm! :) A big thanks for all your help! All the best, Tim.