Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i want to bind data at run time in a pie chart but i do not know the values of x-axis and y-axis

What I have tried:

C#
//dstotal = objemp.getdata();
//string s = dstotal.Tables[0].Rows[0]["Mtotal"].ToString();
//string s1 = dstotal.Tables[1].Rows[0]["Etotal"].ToString();
//int count = Convert.ToInt16(s);
//int count1 = Convert.ToInt16(s1);
string[] xVal = { "Expenses", "Income" };
double[] yVal = { 3, 5 };
Chart1.Series[0].Points.DataBindXY(xVal, yVal);
Chart1.Legends[0].Enabled = true;
Posted
Updated 29-Mar-16 20:37pm
v2
Comments
Dave Kreskowiak 29-Mar-16 10:41am    
OK, so which chart library are you using and what does the documentation on it say about binding data to the chart object?
Member 12423456 30-Mar-16 1:28am    
i am working on 'point of sale' project in it i am to bind no. of stores dynamically on chart control as a division of pie chart and then show no. of managers of corresponding store on chart as a label. I do not know the value of no. of store as they will come from database and i don't know the value of no. of manager as they depends upon the no of stores.... please send me reply as soon as possible

1 solution

ASP.NET 4 and above has a charting control, you can use pie chart from it, but without X,Y axis you are unable to bind pie chart
see below snippet in that i have given a sample to bind pie chart
C#
protected void Page_Load(object sender, EventArgs e)
{
  double[] yValues = { 71.15, 23.19, 5.66 };
  string[] xValues = { "AAA", "BBB", "CCC" };
  Chart1.Series["Default"].Points.DataBindXY(xValues, yValues);
 
  Chart1.Series["Default"].Points[0].Color = Color.MediumSeaGreen;
  Chart1.Series["Default"].Points[1].Color = Color.PaleGreen;
  Chart1.Series["Default"].Points[2].Color = Color.LawnGreen;
 
  Chart1.Series["Default"].ChartType = SeriesChartType.Pie;
 
  Chart1.Series["Default"]["PieLabelStyle"] = "Disabled";
 
  Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
 
  Chart1.Legends[0].Enabled = true;
}

for more details see below link
How to create a Pie chart using ASP.Net and C#[^]
 
Share this answer
 
Comments
Member 12423456 30-Mar-16 2:55am    
no,this is not that what i need. i will explain you in other way by taking an example: if i got 3 rows by using row count property then i want 3 slices of pie chart and then show counts of manager on a particular slice as a label corresponding to store belongs to the manager. i don't know the value of no. of store and manager as they come from database.
koolprasad2003 30-Mar-16 3:17am    
May be this is what you are searching for...see below link
http://www.aspdotnet-suresh.com/2014/06/create-dynamic-ajax-pie-chart-in-aspnet-with-database-example.html
Member 12423456 30-Mar-16 3:35am    
i didn't use ajax toolkit, i drag and drop data chart control from toolbox. and used data access layer for getting data from data base. i need a c# code for how i can divide pie chart into no. of slices as i don't know the no. of slices i will get from database
koolprasad2003 30-Mar-16 3:37am    
Use AJAX control toolkit it is fast and dynamic than only C#, see below link
http://www.aspsnippets.com/Articles/ASPNet-AJAX-Pie-Chart-Control-Populate-from-Database-example.aspx
For C# use
http://www.aspdotnet-pools.com/2014/08/pie-chart-in-aspnet-using-cnet-and-vbnet.html

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900