|
| 1 | +--- |
| 2 | +title: Disable Leged Item Click |
| 3 | +description: This article demonstrates how to disable the click functionality on the legend items in RadHtmlChart for ASP.NET AJAX, preventing the default show/hide behavior of corresponding chart segments. |
| 4 | +type: how-to |
| 5 | +page_title: Disable Leged Item Click |
| 6 | +slug: htmlchart-disable-legend-item-click |
| 7 | +tags: radhtmlchart, asp.net ajax, legend, unclickable, prevent default |
| 8 | +res_type: kb |
| 9 | +ticketid: 1668631 |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | + |
| 14 | +<table> |
| 15 | +<tbody> |
| 16 | +<tr> |
| 17 | +<td>Product</td> |
| 18 | +<td>RadHtmlChart for ASP.NET AJAX</td> |
| 19 | +</tr> |
| 20 | +<tr> |
| 21 | +<td>Version</td> |
| 22 | +<td>All</td> |
| 23 | +</tr> |
| 24 | +</tbody> |
| 25 | +</table> |
| 26 | + |
| 27 | +## Description |
| 28 | + |
| 29 | +I want to disable the ability to click on chart legend items, preventing the default behavior of showing or hiding the corresponding chart segments. |
| 30 | + |
| 31 | +This KB article also answers the following questions: |
| 32 | + |
| 33 | +- How to make legend items in RadHtmlChart non-interactive? |
| 34 | +- How to prevent the default toggle behavior on legend item click in RadHtmlChart? |
| 35 | +- How to stop chart segments from hiding when clicking on their legend items? |
| 36 | + |
| 37 | +## Solution |
| 38 | + |
| 39 | +To make legend items unclickable and prevent the default behavior of showing or hiding the corresponding chart segments in RadHtmlChart, attach the `legendItemClick` event and prevent its default action. |
| 40 | + |
| 41 | +The following example demonstrates how to achieve this by using a Pie Chart as an illustration. However, this approach is applicable to any chart type that supports legend items in RadHtmlChart. |
| 42 | + |
| 43 | +1. Attach the `OnLegendItemClick` client event to the RadHtmlChart. |
| 44 | + |
| 45 | +2. Implement the `onLegendItemClick` function to prevent the default behavior. |
| 46 | + |
| 47 | +Here is how you can configure the RadHtmlChart: |
| 48 | + |
| 49 | +````ASP.NET |
| 50 | +<telerik:RadHtmlChart runat="server" ID="RadChart1" Width="500px"> |
| 51 | + <PlotArea> |
| 52 | + <Series> |
| 53 | + <telerik:PieSeries> |
| 54 | + <SeriesItems> |
| 55 | + <telerik:PieSeriesItem Y="20" Name="name 1" /> |
| 56 | + <telerik:PieSeriesItem Y="30" Name="name 2" /> |
| 57 | + <telerik:PieSeriesItem Y="50" Name="name 3" /> |
| 58 | + <telerik:PieSeriesItem Y="40" Name="name 4" /> |
| 59 | + </SeriesItems> |
| 60 | + </telerik:PieSeries> |
| 61 | + </Series> |
| 62 | + </PlotArea> |
| 63 | + <ClientEvents OnLegendItemClick="onLegendItemClick"/> |
| 64 | +</telerik:RadHtmlChart> |
| 65 | +```` |
| 66 | + |
| 67 | +Include the following JavaScript function in your page: |
| 68 | + |
| 69 | +````JavaScript |
| 70 | +function onLegendItemClick(e) { |
| 71 | + e.preventDefault(); |
| 72 | +} |
| 73 | +```` |
| 74 | + |
| 75 | +By preventing the default action in the `onLegendItemClick` function, clicking on legend items will no longer toggle the visibility of the corresponding chart segments, making the legend items effectively unclickable in terms of interactive behavior. |
| 76 | + |
| 77 | +## See Also |
| 78 | + |
| 79 | +- [RadHtmlChart Documentation](https://docs.telerik.com/devtools/aspnet-ajax/controls/htmlchart/overview) |
| 80 | +- [Client-Side Programming Overview](https://docs.telerik.com/devtools/aspnet-ajax/controls/htmlchart/client-side-programming/overview) |
0 commit comments