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

Multiple StackedBarSeries ItemClick

1 Answer 26 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Stanescu Mihai
Top achievements
Rank 1
Stanescu Mihai asked on 30 Mar 2011, 02:28 PM
Hello Telerik Team,

I have the following scenario, a chart with 2 StackedBarSeriesDefinition. What I did is have an ItemClick event linked up, and what I want to do with it is allow only one StackedBarSeries to trigger the event, and the other to do nothing. What is happenning now is that I can click on either of the BarSeries and trigger the event. 

What I have for the itemssource is a list of 12 items with 2 values, and also the barseries are not in the same StackGroup.

Any suggestions?

1 Answer, 1 is accepted

Sort by
0
Accepted
Evgenia
Telerik team
answered on 01 Apr 2011, 12:42 PM
Hello Stanescu Mihai,

As I was able to understand you want only one Stack of Bars to be selectable on ItemClick. Here is how you can achieve this:
void ChartArea_ItemClick(object sender, ChartItemClickEventArgs e)
{
    if (RadChart1.DefaultView.ChartArea.SelectedItems.Count > 1)
    {
        RadChart1.DefaultView.ChartArea.ClearSelection();
    }
    List<DataPoint> barsInStack = new List<DataPoint>();
    foreach (StackedBar item in this.RadChart1.DefaultView.ChartArea.ChildrenOfType<StackedBar>())
    {
        if (item.DataPoint.XCategory == e.DataPoint.XCategory)
        {
            barsInStack.Add(item.DataPoint);
        }
    }
    RadChart1.DefaultView.ChartArea.SelectItems(barsInStack);
}

You may need to compare the XValue of the DataPoint and not the XCategory depending on your scenario. (marked in the code snippet with yellow).
Have in mind that ChildrenOfType() method is extension method of Telerik.Windows.Controls.dll so you will need to add reference to it.

Greetings,
Evgenia
the Telerik team
Tags
Chart
Asked by
Stanescu Mihai
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
Share this question
or