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

ItemClick event and ItemMapping

1 Answer 72 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Θανάσης
Top achievements
Rank 1
Θανάσης asked on 27 Sep 2010, 12:26 PM
Hi

Let's say I have a bar-chart with two bar series. An AxisX (Product categories) and Cost and Sales (on the same AxisY).
On ItemClick event I'd like to determine which bar the user clicks. Cost or Sales?
I can find X and Y values from event args but I cannot determine if it is the Cost-bar or Sales-bar.

How can I do this?

1 Answer, 1 is accepted

Sort by
0
Evgenia
Telerik team
answered on 30 Sep 2010, 10:20 AM
Hi Thanasis,

Thanks for contacting us. To be able to get the name of the Series you should first set it - you can achieve this by giving some name to LegendLabel property. On ItemClick you will know whether you clicked "Cost" or "Sales" by getting it's LegendLabel. Here is some sample showing this:

InitializeComponent();
         //Bar Chart Series 1
         DataSeries barseries1 = new DataSeries();
         barseries1.LegendLabel = "Cost";
         barseries1.Definition = new BarSeriesDefinition();
         barseries1.Add(new DataPoint() { YValue = 154, XCategory = "Jan" });
         barseries1.Add(new DataPoint() { YValue = 138, XCategory = "Feb" });
         barseries1.Add(new DataPoint() { YValue = 143, XCategory = "Mar" });
         barseries1.Add(new DataPoint() { YValue = 120, XCategory = "Apr" });
         barseries1.Add(new DataPoint() { YValue = 135, XCategory = "May" });
         RadChart1.DefaultView.ChartArea.DataSeries.Add(barseries1);
         //Bar Chart Series 2
         DataSeries barSeries2 = new DataSeries();
         barSeries2.LegendLabel = "Sales";
         barSeries2.Definition = new BarSeriesDefinition();
         barSeries2.Add(new DataPoint() { YValue = 45, XCategory = "Jan" });
         barSeries2.Add(new DataPoint() { YValue = 48, XCategory = "Feb" });
         barSeries2.Add(new DataPoint() { YValue = 53, XCategory = "Mar" });
         barSeries2.Add(new DataPoint() { YValue = 41, XCategory = "Apr" });
         barSeries2.Add(new DataPoint() { YValue = 32, XCategory = "May" });
         RadChart1.DefaultView.ChartArea.DataSeries.Add(barSeries2);
         RadChart1.DefaultView.ChartArea.ItemClick += new EventHandler<ChartItemClickEventArgs>(ChartArea_ItemClick);
     }
     private void ChartArea_ItemClick(object sender, ChartItemClickEventArgs e)
     {
         string name = e.DataSeries.LegendLabel;
         //textBlock1.Text = name;
     }

Hope this helps.

Sincerely yours,
Evgenia
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Chart
Asked by
Θανάσης
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
Share this question
or