ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Add OnClick event on ASP.Net Chart Area using C# and VB.Net<p>Hi <a class="username" rel="Amol111"> Amol111</a>,</p> <p>Refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;asp:Chart ID=&#34;Chart1&#34; runat=&#34;server&#34; Height=&#34;300px&#34; Width=&#34;400px&#34; EnableViewState=&#34;true&#34; OnClick=&#34;Chart1_Click&#34;&gt; &lt;Titles&gt; &lt;asp:Title ShadowOffset=&#34;3&#34; Name=&#34;Items&#34; /&gt; &lt;/Titles&gt; &lt;Legends&gt; &lt;asp:Legend Alignment=&#34;Center&#34; Docking=&#34;Bottom&#34; IsTextAutoFit=&#34;False&#34; Name=&#34;Default&#34; LegendStyle=&#34;Row&#34; /&gt; &lt;/Legends&gt; &lt;Series&gt; &lt;asp:Series Name=&#34;Default&#34; /&gt; &lt;/Series&gt; &lt;ChartAreas&gt; &lt;asp:ChartArea Name=&#34;ChartArea1&#34; BorderWidth=&#34;0&#34; /&gt; &lt;/ChartAreas&gt; &lt;/asp:Chart&gt;</pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Web.UI.DataVisualization.Charting; using System.Data;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Web.UI.DataVisualization.Charting Imports System.Data</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>c#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataTable dt = new DataTable(); dt.Columns.Add(&#34;shipcity&#34;); dt.Columns.Add(&#34;count&#34;); dt.Rows.Add(&#34;India&#34;, 3); dt.Rows.Add(&#34;USA&#34;, 5); dt.Rows.Add(&#34;Germany&#34;, 7); string[] x = new string[dt.Rows.Count]; int[] y = new int[dt.Rows.Count]; for (int i = 0; i &lt; dt.Rows.Count; i++) { x[i] = dt.Rows[i][0].ToString(); y[i] = Convert.ToInt32(dt.Rows[i][1]); } Chart1.Series[0].Points.DataBindXY(x, y); Chart1.Series[0].ChartType = SeriesChartType.Pie; Chart1.ChartAreas[&#34;ChartArea1&#34;].Area3DStyle.Enable3D = true; Chart1.Legends[0].Enabled = true; Chart1.Series[0].PostBackValue = &#34;#VALX&#34;; } } protected void Chart1_Click(object sender, ImageMapEventArgs e) { ClientScript.RegisterClientScriptBlock(this.GetType(), &#34;&#34;, &#34;alert(&#39;&#34; + e.PostBackValue + &#34;&#39;)&#34;, true); }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Not IsPostBack Then Dim dt As DataTable = New DataTable() dt.Columns.Add(&#34;shipcity&#34;) dt.Columns.Add(&#34;count&#34;) dt.Rows.Add(&#34;India&#34;, 3) dt.Rows.Add(&#34;USA&#34;, 5) dt.Rows.Add(&#34;Germany&#34;, 7) Dim x As String() = New String(dt.Rows.Count - 1) {} Dim y As Integer() = New Integer(dt.Rows.Count - 1) {} For i As Integer = 0 To dt.Rows.Count - 1 x(i) = dt.Rows(i)(0).ToString() y(i) = Convert.ToInt32(dt.Rows(i)(1)) Next Chart1.Series(0).Points.DataBindXY(x, y) Chart1.Series(0).ChartType = SeriesChartType.Pie Chart1.ChartAreas(&#34;ChartArea1&#34;).Area3DStyle.Enable3D = True Chart1.Legends(0).Enabled = True Chart1.Series(0).PostBackValue = &#34;#VALX&#34; End If End Sub Protected Sub Chart1_Click(ByVal sender As Object, ByVal e As ImageMapEventArgs) ClientScript.RegisterClientScriptBlock(Me.GetType(), &#34;&#34;, &#34;alert(&#39;&#34; &amp; e.PostBackValue &amp; &#34;&#39;)&#34;, True) End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://i.imgur.com/IDDT53N.gif" alt="" width="264" height="337" /></p>https://www.aspforums.net:443/Threads/186947/Add-OnClick-event-on-ASPNet-Chart-Area-using-C-and-VBNet/https://www.aspforums.net:443/Threads/186947/Add-OnClick-event-on-ASPNet-Chart-Area-using-C-and-VBNet/Wed, 21 Aug 2019 02:05:06 GMT