3 Answers, 1 is accepted
0
Hi Boyd,
You can bind the DataPoint.Label to a data field and then instruct the control to display these labels in the legend via setting the SeriesDefinition.LegendDisplayMode property to the "DataPointLabel" enumeration value like this:
Hope this helps.
Kind regards,
Manuel
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
You can bind the DataPoint.Label to a data field and then instruct the control to display these labels in the legend via setting the SeriesDefinition.LegendDisplayMode property to the "DataPointLabel" enumeration value like this:
public partial class Window1 : Window |
{ |
private static readonly Random rand = new Random(DateTime.Now.Millisecond); |
protected override void OnInitialized(EventArgs e) |
{ |
base.OnInitialized(e); |
PieSeriesDefinition definition = new PieSeriesDefinition(); |
definition.LegendDisplayMode = LegendDisplayMode.DataPointLabel; |
this.RadChart1.DefaultSeriesDefinition = definition; |
this.SetDataMappings("DataTable"); |
this.RadChart1.ItemsSource = GetDataTable(); |
} |
private void SetDataMappings(string seriesLabel) |
{ |
RadChart1.DefaultView.ChartLegend.Header = seriesLabel; |
SeriesMapping seriesMapping = new SeriesMapping(); |
ItemMapping itemMapping = new ItemMapping(); |
itemMapping.DataPointMember = DataPointMember.YValue; |
itemMapping.FieldName = "DoubleData"; |
seriesMapping.ItemMappings.Add(itemMapping); |
ItemMapping itemMapping2 = new ItemMapping(); |
itemMapping2.DataPointMember = DataPointMember.Label; |
itemMapping2.FieldName = "StringData"; |
seriesMapping.ItemMappings.Add(itemMapping2); |
this.RadChart1.SeriesMappings.Add(seriesMapping); |
} |
public static DataTable GetDataTable() |
{ |
DataTable dataTable = new DataTable(); |
dataTable.Columns.Add("DoubleData", typeof(double)); |
dataTable.Columns.Add("StringData", typeof(string)); |
for (int index = 0; index < rand.Next(5, 10); index++) |
{ |
DataRow dataRow = dataTable.NewRow(); |
dataRow["DoubleData"] = rand.Next(0, 100); |
dataRow["StringData"] = string.Format("CustomItem {0}", index); |
dataTable.Rows.Add(dataRow); |
} |
return dataTable; |
} |
} |
Hope this helps.
Kind regards,
Manuel
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jon Masters
Top achievements
Rank 1
answered on 12 Mar 2009, 04:45 PM
Has anyone gotten this code to work?
I've tried and i'm still getting the default labels instead of the labels defined in the DataTable.
I've tried and i'm still getting the default labels instead of the labels defined in the DataTable.
0
Hello Jon Masters,
You just need to replace the DataPointMember.Label mapping to point to DataPointMember.LegendLabel in order to achieve the desired functionality with the latest version of the control (there is now separation between the series item labels and the legend item labels):
Hope this helps.
Greetings,
Manuel
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
You just need to replace the DataPointMember.Label mapping to point to DataPointMember.LegendLabel in order to achieve the desired functionality with the latest version of the control (there is now separation between the series item labels and the legend item labels):
ItemMapping itemMapping2 = new ItemMapping(); |
itemMapping2.DataPointMember = DataPointMember.LegendLabel; |
itemMapping2.FieldName = "StringData"; |
seriesMapping.ItemMappings.Add(itemMapping2); |
Hope this helps.
Greetings,
Manuel
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.