Reputation: 5157
I am making a pie chart & getting the values from Data Table. Here is my code :
.aspx code
<asp:Chart ID="Chart1" runat="server" Width="500px">
<Series>
<asp:Series Name="Series1">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
.cs code
Chart1.Series["Series1"].ChartType = SeriesChartType.Pie;
Chart1.Series["Series1"]["DrawingStyle"] = "Emboss";
Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
Chart1.Series["Series1"].IsValueShownAsLabel = true;
DataTable dt = new DataTable();
DataColumn dc;
con.ConnectionString = ConfigurationManager.ConnectionStrings["mySQLConnection"].ToString();
con.Open();
SqlCommand cmd = new SqlCommand("Select Name, COUNT(code) AS quantity from vTable GROUP BY Name", con1);
var dr = cmd.ExecuteReader();
dt.Load(dr);
Chart1.DataSource = dt;
Chart1.Series["Series1"].XValueMember = "Name";
Chart1.Series["Series1"].YValueMembers = "quantity";
Chart1.DataBind();
I want to show both label with its value on the pie chart. Name column in the SQL query should be shown as label & quantity as value. How it is possible ?
Upvotes: 0
Views: 1376
Reputation: 508
I believe you're looking for DataPointCollection.DataBindXY(IEnumerable, IEnumerable[])
, MSDN.
Example:
string[] Names = new string[] { "Item1", "Item2", "Item3" };
double[] Values = new double[] { 0.1, 0.2, 0.3 };
chart1.Series[0].Points.DataBindXY(Names, Values);
Hope that get you in the right direction!
Upvotes: 1