Click here to Skip to main content
15,895,831 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Dear Friends,

Here ianm Binding my dataset values to Aspx Chart i have written a code for that But the Legend Text is Coming but the x value and Y values are Not Displaying.

This is My code:
C#
private void BindChartData()
   {
       DataSet ds = new DataSet(); //Getting the dataSet
       ds = rpt.GetComputersDetailsByDistrictRespdent();
       //Get the no of series first.. this will be a distinct series list..
       List<string> seriesList = new List<string>();
       foreach (DataRow row in ds.Tables[0].Rows)
       {
           string seriesName = row["Computers Per Category"].ToString();
           if (!seriesList.Contains(seriesName))
               seriesList.Add(seriesName);
       }
       //Now bind the xValues and yVlaues for each series
       foreach (string seriesName in seriesList)
       {
           List<string> xValues = new List<string>();
           List<int> yValues = new List<int>();

           foreach (DataRow row in ds.Tables[0].Rows)
           {
               string xValue = row["District Names"].ToString();
               int yValue = Convert.ToInt32(row["No of Computers"]);
               string sName = row["Respondent"].ToString();

               if (sName == seriesName)
               {
                   xValues.Add(xValue);
                   yValues.Add(yValue);
               }
           }
           Chart1.Series.Add(seriesName);
           Chart1.Series[seriesName].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Bar;
           Chart1.Series[seriesName].ChartArea = "ChartArea1";
           Chart1.Series[seriesName].Legend = "Legend1";
           Chart1.Series[seriesName].LegendText = seriesName;
           Chart1.Series[seriesName].Points.DataBindXY(xValues, yValues);
       }
   }


Please Check where i have done Mistake.

Regards,

AnilKumar.D
Posted
Updated 16-Jul-12 21:08pm
v2

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