i try to get data in highchart for this i try this
public class Category
{
public string CatgType { get; set; }
public string ProgName { get; set; }
public int totalStudents { get; set; }
}
[WebMethod]
public List<Category> StudentAnalysis(string category)
{
List<Category> studentInfos = new List<Category>();
DataSet ds = new DataSet();
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[1].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "GetCategoriesChart";
cmd.CommandType = CommandType.StoredProcedure;
if (category == "")
{
cmd.Parameters.AddWithValue("@Category", null);
}
else
{
cmd.Parameters.AddWithValue("@Category", category);
}
cmd.Connection = con;
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fill(ds, "Studentinfo");
}
}
}
if (ds != null)
{
if (ds.Tables.Count > 0)
{
if (ds.Tables["Studentinfo"].Rows.Count > 0)
{
foreach (DataRow dr in ds.Tables["Studentinfo"].Rows)
{
studentInfos.Add(new Category
{
CatgType = dr["Catg_type"].ToString(),
ProgName = dr["Prog_name"].ToString(),
totalStudents = Convert.ToInt32(dr["total_students"])
});
}
}
}
}
return studentInfos;
}
jquery
<script type="text/javascript">
$(document).ready(function () {
var cat = {};
cat.category = '';
GetCategories(cat);
});
$("[id*=ddlCategory]").change(function () {
var cat = {};
cat.category = $(this).val();
if ($(this).val() == '--Select--') {
cat.category = '';
}
GetCategories(cat);
});
function GetCategories(cate) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "WebForm4.aspx/StudentAnalysis",
data: JSON.stringify(cate),
dataType: "json",
success: function (Result) {
Result = Result.d;
var uniqueCat = [];
var uniqueProgName = [];
$.map(Result, function (ele) {
if (uniqueCat.indexOf(ele.CatgType) == -1)
uniqueCat.push(ele.CatgType);
if (uniqueProgName.indexOf(ele.ProgName) == -1)
uniqueProgName.push(ele.ProgName);
});
var seriesData = [];
$.each(uniqueProgName, function () {
var series = {};
var progName = $(this)[0];
series.name = progName;
var s = $.grep(Result, function (e) {
return e.ProgName == progName;
});
series.data = $.map(s, function (e) { return e.totalStudents });
seriesData.push(series);
});
DreawChart(uniqueCat, seriesData);
},
error: function (error) {
debugger;
var r = error.responseText;
var errorMessage = r.Message;
alert(errorMessage);
alert(r);
alert(Error);
}
});
}
function DreawChart(series, seriesData) {
$('#container').highcharts({
chart: {
type: 'bar',
renderTo: 'container'
},
title: {
text: 'Studentinfo'
}, xAxis: {
categories: eval(series)
},
yAxis: {
title: {
text: 'Figures'
}
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: JSON.parse(JSON.stringify(seriesData))
});
}
</script>
<body>
<form id="form1" runat="server">
<div id="container">
</div>
<asp:DropDownList runat="server" ID="ddlCategory">
<asp:ListItem Text="--Select--" />
<asp:ListItem Text="Management" />
<asp:ListItem Text="Finance" />
<asp:ListItem Text="ComputerScience" />
</asp:DropDownList>
<%-- <div>
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
</div>
<asp:Button ID="Button1" runat="server" Text="Button" />--%>
</form>
</body>
when i try to display tthis shows an error
<!DOCTYPE html>
<html>
<head>
<title>Unknown web method StudentAnalysis.<br>Parameter name: methodName</title>
<meta name="viewport" content="width=device-width" />
<style>
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Consolas","Lucida Console",Monospace;font-size:11pt;margin:0;padding:0.5em;line-height:14pt}
.marker {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
@media screen and (max-width: 639px) {
pre { width: 440px; overflow: auto; white-space: pre-wrap; word-wrap: break-word; }
}
@media screen and (max-width: 479px) {
pre { width: 280px; }
}
</style>
</head>
<body bgcolor="white">
<span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>
<h2> <i>Unknown web method StudentAnalysis.<br>Parameter name: methodName</i> </h2></span>
<font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">
<b> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
<br><br>
<b> Exception Details: </b>System.ArgumentException: Unknown web method StudentAnalysis.<br>Parameter name: methodName<br><br>
<b>Source Error:</b> <br><br>
<table width=100% bgcolor="#ffffcc">
<tr>
<td>
<code>
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</code>
</td>
</tr>
</table>
<br>
<b>Stack Trace:</b> <br><br>
<table width=100% bgcolor="#ffffcc">
<tr>
<td>
<code><pre>
[ArgumentException: Unknown web method StudentAnalysis.
Parameter name: methodName]
System.Web.Script.Services.WebServiceData.GetMethodData(String methodName) +261
System.Web.Handlers.ScriptModule.OnPostAcquireRequestState(Object sender, EventArgs eventArgs) +224
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +176
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +169
</pre></code>
</td>
</tr>
</table>
<br>
<hr width=100% size=1 color=silver>
<b>Version Information:</b> Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.36366
</font>
</body>
</html>
<!--
[ArgumentException]: Unknown web method StudentAnalysis.
Parameter name: methodName
at System.Web.Script.Services.WebServiceData.GetMethodData(String methodName)
at System.Web.Handlers.ScriptModule.OnPostAcquireRequestState(Object sender, EventArgs eventArgs)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
-->