try to get data in highchart for this i try this
Here is my class
public class Category
{
public string Name { get; set; }
public string Employees{ get; set; }
public int totalStudents { get; set; }
}
[WebMethod]
public static 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;
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
{
Name= dr["Name"].ToString(),
Employees= dr["Employees"].ToString(),
totalStudents = Convert.ToInt32(dr["Employees"])
});
}
}
}
}
return studentInfos;
}
Javascript
<script type="text/javascript">
$(document).ready(function () {
var cat = {};
cat.category = '';
GetCategories();
});
function GetCategories() {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "WebForm4.aspx/StudentAnalysis",
// data: JSON.stringify(cate),
data: JSON.stringify(),
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: 'pie',
renderTo: 'container'
},
title: {
text: 'Studentinfo'
}, xAxis: {
categories: eval(series)
},
yAxis: {
title: {
text: 'Figures'
}
},
plotOptions: {
pie: {
innerSize: 100,
depth: 45,
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.1f} %',
style: {
color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
}
}
}
},
series: JSON.parse(JSON.stringify(seriesData))
});
}
</script>
Data
Name Employees
ABC 68
DEF 481
EFG 886
XDE 567
DFG 452
i try pie chart now in chart abc def not display like only 1 data is display in chart i.e. 68 how i display all data with names?