Imagine you have a databound RadChart and you need to customize the item labels, say you need to combine the values of two fields into a single item label. All you need to do is wire the ItemDataBound event, retrieve the ChartSeriesItem and customize it as per your requirements. You may use the actual data for this, here is an example:
protected void RadChart1_ItemDataBound(object sender, ChartItemDataBoundEventArgs e)
ChartSeriesItem item = e.SeriesItem;
DataRowView dataItem = (DataRowView)e.DataItem;
item.Label.TextBlock.Text = dataItem["FirstName"].ToString() + " " + dataItem["LastName"].ToString();
That was simple, but what about auto-generated axis items? OK, let’s start with some background – RadChart allows you to modify it at any stage of the page lifecycle, including events fired as late as Page_PreRenderComplete. And still its axes will be auto-scaled showing the range needed for the data being shown. So, how to take advantage of RadChart’s smart axes, but customize their items? Another event comes in handy – BeforeLayout. It is fired after the axis items are created, but before the start of the layout calculations, so the following code will produce Y axis labels with alternating size:
Finally – yes, you can use the same approach for the auto-generated legend items :-)
Hope you have fun customizing RadChart.
Subscribe to be the first to get our expert-written articles and tutorials for developers!