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

Bar Chart - Active Region click event

3 Answers 180 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Preetam Ray
Top achievements
Rank 1
Preetam Ray asked on 06 Nov 2008, 02:44 PM
Hi All,
    In our application we have a dynamically generated Bar Chart and to this bar chart we are creating ChartSeries and adding ChartSeries item and while adding the items to the series i am trying to register a click event for the ActiveRegion and the code is as below in bold but the event never gets fired.

ChartSeries

s0 = new ChartSeries();  

s0.Name =

 

string.Empty;  

 

for (int ic = 0; ic < dt.Rows.Count; ic++)  

 

ChartSeriesItem seriesItem = new ChartSeriesItem();  

seriesItem.YValue = (

 

double)dt.Rows[ic]["Quantity"];  

seriesItem.Name =

 

"Settlement";  

seriesItem.Appearance.Border.Color =

 

Color.Black;  

 

DateTime dt1 = Convert.ToDateTime(dt.Rows[ic]["Date"]);  

seriesItem.XValue = dt1.ToOADate();

seriesItem.ActiveRegion.Click +=

 

new RegionClickEventHandler(ActiveRegion_Click);  

seriesItem.ActiveRegion.Tooltip =

"Number of News:" + dt.Rows[ic]["Quantity"] + "";  

 

 

RadToolTipManager1.TargetControls.Add(

null, seriesItem.ActiveRegion.Tooltip.ToString(), true);  

 

 

s0.AddItem(seriesItem);

}

 

 

radchart1.Series.Add(s0); 
I even tried the below  way of registering the click event for the Active region at chart level but in vain.

 

radchart1.ChartTitle.ActiveRegion.Click +=

 

new RegionClickEventHandler(ActiveRegion_Click);

Please correct me if i am doing something wrong.

Regards,
Preetam.

 

 

3 Answers, 1 is accepted

Sort by
0
Ves
Telerik team
answered on 10 Nov 2008, 09:19 AM
Hello Preetam Ray,

It seems you have hit a bug in RadChart. Please, use RadChart.Click event for the time being. You can check the type of args.Element in its event handler, to determine the element which fired it.

Your Telerik points have been updated.

Regards,
Ves
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Katie Arnott
Top achievements
Rank 1
answered on 25 Mar 2011, 06:59 PM
Using this workaround, can you disable the chart's title click and legend click? I do not want them to be clickable.

Thanks
0
Ves
Telerik team
answered on 30 Mar 2011, 11:35 AM
Hello Katie,

This is a typical html output from RadChart:

<div id="RadChart1" class="RadChart" style="height:364px;width:767px;">
    <img alt='' style='border-width: 0px;' usemap='#imRadChart1' src='ChartImage.axd?UseSession=true&ChartID=515c08c7-31c3-4492-b8c1-44723c8fdee0_chart_RadChart1&imageFormat=Png&random=0.898192182135858' onerror="if(confirm('Error loading RadChart image.\nYou may also wish to check the ASP.NET Trace for further details.\nDisplay stack trace?'))window.location.href=this.src;" /><map id='imRadChart1' name='imRadChart1'>
<area shape="rect" href="javascript:__doPostBack('RadChart1','true,0,0')" coords="98,108,225,320" alt="" title=""  />
<area shape="rect" href="javascript:__doPostBack('RadChart1','true,0,1')" coords="267,66,394,320" alt="" title=""  />
<area shape="rect" href="javascript:__doPostBack('RadChart1','true,0,2')" coords="435,193,562,320" alt="" title=""  />
<area shape="poly" href="javascript:__doPostBack('RadChart1','false,1,2,0')" coords="692,181,692,184,690,186,687,186,684,186,682,184,682,181,682,179,684,176,687,176,690,176,692,179,692,181" alt="" title=""  />
<area shape="rect" href="javascript:__doPostBack('RadChart1','false,1,2')" coords="681,172,749,192" alt="" title=""  />
<area shape="rect" href="javascript:__doPostBack('RadChart1','false,1')" coords="678,170,751,194" alt="" title=""  />
<area shape="rect" href="javascript:__doPostBack('RadChart1','false,2')" coords="55,16,184,52" alt="" title=""  /></map><input id="RadChart1_ClientState" name="RadChart1_ClientState" type="hidden" />
</div>
    </div>

In order to disable the postback for the legend and title you will need to add a javascript function which removes the last several area elements of the image map. The very last one is for the title and  the number of elements for the legend is 2*n + 1 where n stands for the number of legend items. That is 3 <area> elements for 1 legend item, 5 for 2 legend items, etc.

You can also distinguish them by the value of the second parameter of __doPostBack -- it is a string, which represents several values, separated by commas. The second one is 0 for PlotArea items (bars, points etc.). It is 1 for the legend items and 2 for the ChartTitle (highlighted in the above snippet).

Best regards,
Ves
the Telerik team
Tags
Chart (Obsolete)
Asked by
Preetam Ray
Top achievements
Rank 1
Answers by
Ves
Telerik team
Katie Arnott
Top achievements
Rank 1
Share this question
or