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

Pie Chart initial selection

1 Answer 29 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Roland
Top achievements
Rank 1
Roland asked on 05 Dec 2012, 01:47 AM
Hi,

I have a data bound Pie Chart with single selection enabled.  What I want to do is after the ItemsSource has been loaded (asynchronously) is to have the first item in the chart selected.  How can I do this?

I've tried calling ChartArea.SelectItem(index) right after the data has been loaded, but the chart series and items are still not created at that point.  Also tried calling SelectItem on various events (ItemDataBound, DataBound, Loaded), but to no avail.

1 Answer, 1 is accepted

Sort by
0
Missing User
answered on 07 Dec 2012, 04:19 PM
Hi Roland,

The reason why the pie chart cannot select a default item is because interactivity settings are meant to be used with a mouse and the selection fails when the chart hasn't been rendered yet.

You can, however, use the following workaround involving a combination of the DataBound and LayoutUpdated events:
void RadChart1_DataBound(object sender, Telerik.Windows.Controls.Charting.ChartDataBoundEventArgs e)
{
    if (!this.TrySelectItem())
    {
        this.RadChart1.LayoutUpdated += this.RadChart1_LayoutUpdated;
    }
}
 
void RadChart1_LayoutUpdated(object sender, EventArgs e)
{
    if (this.TrySelectItem())
    {
        this.RadChart1.LayoutUpdated -= this.RadChart1_LayoutUpdated;
    }
}
 
private bool TrySelectItem()
{
    this.RadChart1.DefaultView.ChartArea.SelectItem(0);
    return this.RadChart1.DefaultView.ChartArea.SelectedItems.Count != 0;
}


Kind regards,
Ivan N.
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Chart
Asked by
Roland
Top achievements
Rank 1
Answers by
Missing User
Share this question
or