Implement Open Source charts in ASP.Net JavaScript AJAX SQL Server jQuery HTML5 C#

Complete CODE is given below:
Here he has explained with an example, how to implement Open Source charts in ASP.Net using C# and VB.Net.
The Chart.js library is an Open Source Chart library which uses HTML5 Canvas for creating Charts.
The HTML5 Canvas charts will be populated from database using jQuery AJAX in ASP.Net.
https://www.aspsnippets.com/categories//articles/implement-open-source-charts-in-aspnet.aspx

Country:









using System.Data;
using System.Text;
using System.Web.Services;
using System.Data.SqlClient;
using System.Configuration;

[WebMethod]
public static string GetChart(string country)
{
string constr = ConfigurationManager.ConnectionStrings[“ConString”].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
string query = string.Format(“select shipcity, count(orderid) from orders where shipcountry = ‘{0}’ group by shipcity”, country);
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = query;
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
StringBuilder sb = new StringBuilder();
sb.Append(“[“);
while (sdr.Read())
{
sb.Append(“{“);
System.Threading.Thread.Sleep(50);
string color = String.Format(“#{0:X6}”, new Random().Next(0x1000000));
sb.Append(string.Format(“text :'{0}’, value:{1}, color: ‘{2}'”, sdr[0], sdr[1], color));
sb.Append(“},”);
}
sb = sb.Remove(sb.Length – 1, 1);
sb.Append(“]”);
con.Close();
return sb.ToString();
}
}
}
}



Post Author: hatefull