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

Custom ItemLabelFormat

1 Answer 58 Views
Chart
This is a migrated thread and some comments may be shown as answers.
rachel
Top achievements
Rank 1
rachel asked on 06 Dec 2011, 10:26 AM
i'm using with the pie.
my ItemLabelFormat #%{P2} #XCAT becouse i want to display the category name.
my category name is enum, and i want to display the description by the enum.
Hou could i do that?

1 Answer, 1 is accepted

Sort by
0
Petar Marchev
Telerik team
answered on 08 Dec 2011, 04:43 PM
Hi Rachel,

There is no way to achieve this out of the box.
One way to accomplish your goal is to create an additional property in your business class which returns this metadata.

public class Product
{
 public ProductName Name { get; set; }
 public double Value { get; set; }
 
 private string nameDescription;
 public string NameDescription
 {
  get
  {
    if(this.nameDescription == null) this.nameDescription = GetEnumDescription(this.Name);
    return this.nameDescription;
  }
}
 
public static string GetEnumDescription(Enum value)
{
  FieldInfo fi = value.GetType().GetField(value.ToString());
 
  DescriptionAttribute[] attributes =
    (DescriptionAttribute[])fi.GetCustomAttributes(
    typeof(DescriptionAttribute),
    false);
 
  if (attributes != null &&
    attributes.Length > 0)
    return attributes[0].Description;
  else
    return value.ToString();
 
 }
}
 
public enum ProductName
{
  [Description("Xbox descr")]
  Xbox,
 
  [Description("TvSet descr")]
  TvSet,
 
  [Description("Telephone descr")]
  Telephone,
 
  [Description("Desktop descr")]
  Desktop
}

Now, you need to set the FieldName in the ItemMapping to be this new property.
<telerik:ItemMapping DataPointMember="XCategory" FieldName="NameDescription" />

Hope this helps.

Best wishes,
Petar Marchev
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
Chart
Asked by
rachel
Top achievements
Rank 1
Answers by
Petar Marchev
Telerik team
Share this question
or