Responding to Server Events
RadChart has been deprecated since Q3 2014 and is no longer recommended for use, as it does not support modern browsers. We strongly recommend using RadHtmlChart, Telerik's modern client-side charting component. To transition from RadChart to RadHtmlChart, refer to the following migration articles:
Explore the RadHtmlChart documentation and online demos to determine how it fits your development needs.
Use the RadChart OnClick event to handle server postbacks caused by clicking on areas of the chart. Elements of the chart that have an ActiveRegion property can be used for information inside the OnClick event handler. The example below shows some of the commonly used chart elements that react to clicks including the chart title, x and y axis labels, series legends and items. The code example below shows a RadChart OnClick event handler evaluating the ChartClickEventArgs "Args" parameter. Use the Args.Element.ActiveRegion property to access the ToolTip, Url and Attributes for the ActiveRegion.
private void radChart1_Load(object sender, EventArgs e)
{
radChart1.ChartTitle.ActiveRegion.Click += new RegionClickEventHandler(Region_Click);
foreach (ChartSeries series in radChart1.Series) { foreach (ChartSeriesItem item in series.Items) { item.ActiveRegion.Click += new RegionClickEventHandle(Region_Click); } }
}
void Region_Click(object sender, RegionClickEventArgs args)
{
string logFormat = "Item Class:{0} - \"{1}\"" + Environment.NewLine;
if (sender is ChartTitle) { tbLog.Text += String.Format(logFormat, sender.GetType().Name, (sender as ChartTitle).TextBlock.Text); } else if (sender is ChartSeriesItem) { tbLog.Text += String.Format(logFormat, sender.GetType().Name, (sender as ChartSeriesItem).Name); }
}
To react to server events in RadChart handle the Click event for a report item ActiveRegion in code. Determine the type of the clicked object by checking the "sender" object passed to the event handler. Cast "sender" to that type to use its properties and methods. See the code example below. In the radChart1_Load the ChartTitle and ChartSeriesItems both have ActiveRegion properties. The ActiveRegion.Click is assigned the "Region_Click" event handler. In "Region_Click" the Sender class is determined. For example if Sender is a ChartTitle type, Sender is cast to be a ChartTitle and its TextBlock.Text property is accessed.
private void radChart1_Load(object sender, EventArgs e)
{
radChart1.ChartTitle.ActiveRegion.Click += new RegionClickEventHandler(Region_Click);
foreach (ChartSeries series in radChart1.Series) { foreach (ChartSeriesItem item in series.Items) { item.ActiveRegion.Click += new RegionClickEventHandler(Region_Click); } }
}
void Region_Click(object sender)
{
string logFormat = "Item Class:{0} - \"{1}\"" + Environment.NewLine;
if (sender is ChartTitle) { tbLog.Text += String.Format(logFormat, sender.GetType().Name, (sender as ChartTitle).TextBlock.Text); } else if (sender is ChartSeriesItem) { tbLog.Text += String.Format(logFormat, sender.GetType().Name, (sender as ChartSeriesItem).Name); }
}