Formatting Chart and Legend Labels

4 posts, 0 answers
  1. Bryan Johnson
    Bryan Johnson avatar
    18 posts
    Member since:
    May 2010

    Posted 11 Oct 2010 Link to this post

    I am trying to format a column called 'Month' using the 3-character month abbreviation in my data grid which is bound to a bar chart.  My grid and chart are based on this demo example:  http://demos.telerik.com/silverlight/#Chart/Aggregates.  Basically, the grid compiles data and summarizes by Year, Quarter, Month, and then some other categories as well.  For the Month column, I tried two different methods (for sorting purposes, I have to use an integer or some date value for the month).  First, I just made Month an integer field and then used a converter mapped in the xaml for the 'Month' field to display 'JAN', 'FEB', etc.  This worked fine for the grid, but the chart would display 1, 2, etc. instead of the month abbreviation.  I researched this and was not able to come up with a solution to map the converter to the chart.  So, I tried making the Month field a datetime and then set the value to 1/1/1900, 2/1/1900, etc. and specified the format of the field to 'MMM' in the xaml for the grid.  I then used the following statement to set the the format in the chart when the user grouped by month:

    SalesAnalysisChart.DefaultView.ChartArea.AxisX.DefaultLabelFormat = "MMM";


    This partially worked in that when the months were displayed across the x-axis they were labeled properly, but not when they appeared in the legend (the user, of course, can group by any of the columns which may or may not include month).  I've tried setting LegendItemLabelFormat, ItemLabelFormat, etc. but without success.  I'm not sure of the element on which to set the property.  I only need to change the default format for just the Month column - all other columns should display normally when grouped.  I also came across a class called 'LegendItemFormatConverter' which looks promising but I can't find any examples as to how to implement it.  I would actually prefer the converter method because the converter I wrote displays the month abbreviation in all caps, whereas the 'MMM' format displays in upper/lower case.  Here is the converter code that I originally used for the grid:

    using System;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Ink;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using System.Windows.Data;
      
    namespace ApolloSL
    {
        public class MonthConverter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                if (value != null)
                
                    DateTime date = new DateTime(1900, (Int32)value, 1);
                    return date.ToString("MMM").ToUpper();
                }
                else
                { return ""; }
            }
      
            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                return value.ToString();
            }
        }
    }

    Please help...

    Thank you in advance for your assistance,
    Bryan Johnson

  2. Bryan Johnson
    Bryan Johnson avatar
    18 posts
    Member since:
    May 2010

    Posted 13 Oct 2010 Link to this post

    Any help on this?
  3. Vladimir Milev
    Admin
    Vladimir Milev avatar
    1061 posts

    Posted 14 Oct 2010 Link to this post

    Hello Bryan Johnson,

    Unfortunately the legend text cannot be currently customized when you are using grouping and aggregation. The reason is that it is generated on top of the keys used for the grouping of the data. We have other customers also looking to do that and have planned to address this issue in the future as it seems to limit the flexibility of our control.

    Greetings,
    Vladimir Milev
    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
  4. Bryan Johnson
    Bryan Johnson avatar
    18 posts
    Member since:
    May 2010

    Posted 14 Oct 2010 Link to this post

    Thanks for the reply.  It would be a nice feature to have, though.

    Best Regards,
    Bryan
Back to Top