Click here to Skip to main content
15,888,313 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to create pie chart,binding records from sqlserver database.I have to in c# coding without adding webservices method.

What I have tried:

Already done using webservies

C#
<pre lang="c#">        }
        [WebMethod]
        public List<FruitEnity> FruitAnalysis()
        {
            List<FruitEnity> fruitinfo = new List<FruitEnity>();
            DataSet ds = new DataSet();
            using (SqlConnection con = new SqlConnection("Data Source=XXXX;User Id=XXXX;
            Password=XXXX;DataBase=XXXX"))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.CommandText = "select name,value from tbl_fruitanalysis";
                    cmd.Connection = con;
                    using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                    {
                        da.Fill(ds, "FruitAnalysis");
                    }
                }
            }
            if (ds != null)
            {
                if (ds.Tables.Count > 0)
                {
                    if (ds.Tables["FruitAnalysis"].Rows.Count > 0)
                    {
                        foreach (DataRow dr in ds.Tables["FruitAnalysis"].Rows)
                        {
                            fruitinfo.Add(new FruitEnity { Name = dr["name"].ToString(),
                            Value = Convert.ToInt32(dr["value"]) });
                        }
                    }
                }
            }
            return fruitinfo;
        }
Posted
Updated 8-May-17 1:02am

1 solution

For an SQL Server example, see: HighCharts databinding in C#[^]

Here is a pure HTML example:
DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <title>Bar Chart</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
    <script src="http://code.highcharts.com/highcharts.js" type="text/javascript"></script>
      <script src="http://code.highcharts.com/modules/exporting.js" type="text/javascript"></script>

      <script type="text/javascript">
          $(function() {
              $('#container').highcharts({
                  chart: {
                      type: 'bar'
                  },
                  title: {
                      text: 'MyFruit database info'
                  },
                  xAxis: {
                      categories: ['Records', 'Fragmentation', 'Users']
                  },
                  yAxis: {
                      title: {
                          text: 'Values'
                      }
                  },
                  series: [
                      {
                          name: 'MyFruit_Sites',
                          data: [10, 50, 4]
                      }, {
                          name: 'MyFruit_Devices',
                          data: [500, 80, 3]
                      }
                  ]
              });

			  // the button handler
			  $('#button').click(function () {
				  var chart = $('#container').highcharts();
				  chart.addSeries({
							  name: 'MyFruit_Users',
							  data: [30, 60, 4]
						  });
				});
          });
      </script>
  </head>
  <body>
    <div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
      <button id="button" class="autocompare">Add series</button>
  </body>
</html>
 
Share this answer
 
v2
Comments
GrpSMK 8-May-17 8:43am    
i need to fetch data from db.
RickZeeland 8-May-17 12:35pm    
Just fetch the data from the db and generate html from that, or maybe a separate json file.

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