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.Display percentage values in Pie Chart using C# and VB.Net in ASP.Net<p>Hi&nbsp;Tevin,</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">Database</span></strong></p> <p>For this example I have used of Northwind database that you can download using the link given below.</p> <p><a href="https://www.aspsnippets.com/Articles/Install-Microsoft-Northwind-and-Pubs-Sample-databases-in-SQL-Server-Management-Studio.aspx" target="_blank">Download Northwind Database</a></p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;asp:Chart ID=&#34;PieChartMonthToDate&#34; BorderlineColor=&#34;Black&#34; BorderlineDashStyle=&#34;Solid&#34; Visible=&#34;true&#34; ImageType=&#34;Png&#34; runat=&#34;server&#34; Height=&#34;400px&#34; Width=&#34;400px&#34; PaletteCustomColors=&#34;128, 255, 128; 255, 128, 0&#34;&gt; &lt;Titles&gt; &lt;asp:Title TextStyle=&#34;Frame&#34;&gt; &lt;/asp:Title&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;Column&#34;&gt; &lt;/asp:Legend&gt; &lt;/Legends&gt; &lt;Series&gt; &lt;asp:Series Name=&#34;Series1&#34; ChartType=&#34;Pie&#34; YValuesPerPoint=&#34;2&#34;&gt; &lt;/asp:Series&gt; &lt;/Series&gt; &lt;ChartAreas&gt; &lt;asp:ChartArea IsSameFontSizeForAllAxes=&#34;true&#34; BorderWidth=&#34;0&#34; Name=&#34;ChartArea1&#34;&gt; &lt;Area3DStyle Enable3D=&#34;true&#34; /&gt; &lt;/asp:ChartArea&gt; &lt;/ChartAreas&gt; &lt;/asp:Chart&gt;</pre> <p><strong><span style="text-decoration: underline;">Namespaces</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Configuration; using System.Data.SqlClient; using System.Web.UI.DataVisualization.Charting;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Configuration Imports System.Data.SqlClient Imports System.Web.UI.DataVisualization.Charting</pre> <p><strong><span style="text-decoration: underline;">Code</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[&#34;ConString&#34;].ConnectionString)) { using (SqlCommand cmd = new SqlCommand(&#34;select shipcity, count(orderid) Total from orders where shipcountry = &#39;Brazil&#39; group by shipcity&#34;, conn)) { Series series = PieChartMonthToDate.Series[&#34;Series1&#34;]; conn.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { series.Points.AddXY(rdr[&#34;shipcity&#34;].ToString(), rdr[&#34;Total&#34;.ToString()]); PieChartMonthToDate.Series[&#34;Series1&#34;].Label = &#34;#PERCENT{P2}&#34;; PieChartMonthToDate.Series[&#34;Series1&#34;].LegendText = &#34;#VALX&#34;; PieChartMonthToDate.Legends[0].LegendStyle = LegendStyle.Column; PieChartMonthToDate.Legends[0].Docking = Docking.Right; PieChartMonthToDate.Legends[0].Alignment = System.Drawing.StringAlignment.Center; } rdr.Close(); } } } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load If Not IsPostBack Then Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings(&#34;ConString&#34;).ConnectionString) Using cmd As New SqlCommand(&#34;select shipcity, count(orderid) Total from orders where shipcountry = &#39;USA&#39; group by shipcity&#34;, conn) Dim series As Series = PieChartMonthToDate.Series(&#34;Series1&#34;) conn.Open() Dim rdr As SqlDataReader = cmd.ExecuteReader() While rdr.Read() series.Points.AddXY(rdr(&#34;shipcity&#34;).ToString(), rdr(&#34;Total&#34;.ToString())) PieChartMonthToDate.Series(&#34;Series1&#34;).Label = &#34;#PERCENT{P2}&#34; PieChartMonthToDate.Series(&#34;Series1&#34;).LegendText = &#34;#VALX&#34; PieChartMonthToDate.Legends(0).LegendStyle = LegendStyle.Column PieChartMonthToDate.Legends(0).Docking = Docking.Right PieChartMonthToDate.Legends(0).Alignment = System.Drawing.StringAlignment.Center End While rdr.Close() End Using End Using End If End Sub</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><strong><span style="text-decoration: underline;"><img src="https://i.imgur.com/6928oR0.jpg" alt="" width="374" height="247" /></span></strong></p>https://www.aspforums.net:443/Threads/696880/Display-percentage-values-in-Pie-Chart-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/696880/Display-percentage-values-in-Pie-Chart-using-C-and-VBNet-in-ASPNet/Mon, 15 Jul 2019 04:39:24 GMT