I have DataTable fixed i want to bind that data for HighChart. How to do that?
HTML
<html>
<head>
<title>Highcharts Demo</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script language="JavaScript">
$(document).ready(function () {
var title = {
text: 'Average Numbers of Admission in Year 2022-2023'
};
var subtitle = {
text: 'Source: GANPAT UNIVERSITY'
};
var xAxis = {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
};
var yAxis = {
title: {
text: 'Avg. No. of Students'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
};
var tooltip = {
valueSuffix: ' Students'
}
var legend = {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
};
var series = [{
name: 'UVPC',
data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2,
26.5, 23.3, 18.3, 13.9, 9.6]
},
{
name: 'IOT',
data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8,
24.1, 20.1, 14.1, 8.6, 2.5]
},
{
name: 'AMPICS',
data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0,
16.6, 14.2, 10.3, 6.6, 4.8]
}
];
var json = {};
json.title = title;
json.subtitle = subtitle;
json.xAxis = xAxis;
json.yAxis = yAxis;
json.tooltip = tooltip;
json.legend = legend;
json.series = series;
PostAjaxRequest('HighChartDemo.aspx/GetInstituteAvg', '', '', 'json', '{}');
$('#container').highcharts(json);
});
</script>
</head>
<body>
<div id = "container" style = "width: 550px; height: 400px; margin: 0 auto"></div>
</body
</html>
C#
public static Dictionary<string, GetAdmissionData> GetInstituteAvg()
{
try
{
BaseDAL bd3 = new BaseDAL();
DataTable dt = GetTable();
List<string> lst = new List<string>();
Dictionary<string, GetAdmissionData> dic = new Dictionary<string, GetAdmissionData>();
for (int i = 0; i < dt.Rows.Count; i++)
{
GetAdmissionData sd = new GetAdmissionData();
sd.Institute = dt.Rows[i].Field<string>("Institute");
sd.Avg = dt.Rows[i].Field<int>("Avg");
sd.MonthName = dt.Rows[i].Field<string>("MonthName");
}
return dic;
}
catch (Exception ex)
{
}
}
public class GetAdmissionData
{
public string Institute { get; set; }
public int Avg { get; set; }
public string MonthName { get; set; }
}
static DataTable GetTable()
{
DataTable dt = new DataTable();
dt.Columns.Add("Institute", typeof(string));
dt.Columns.Add("Avg", typeof(int));
dt.Columns.Add("MonthName", typeof(int));
dt.Rows.Add("A", 80, "Jan");
dt.Rows.Add("A", 20, "Jan");
dt.Rows.Add("A", 40, "Jan");
dt.Rows.Add("A", 10, "Jan");
dt.Rows.Add("A", 11, "Jan");
dt.Rows.Add("B", 21, "Feb");
dt.Rows.Add("B", 22, "Feb");
dt.Rows.Add("B", 23, "Feb");
dt.Rows.Add("B", 24, "Feb");
dt.Rows.Add("B", 25, "Feb");
dt.Rows.Add("B", 26, "Feb");
dt.Rows.Add("C", 16.5, "March");
dt.Rows.Add("C", 17, "March");
dt.Rows.Add("C", 18, "March");
dt.Rows.Add("C", 19, "March");
dt.Rows.Add("C", 20, "March");
dt.Rows.Add("D", 90, "April");
dt.Rows.Add("D", 12, "April");
dt.Rows.Add("D", 3, "April");
dt.Rows.Add("D", 5, "April");
dt.Rows.Add("D", 6, "April");
return dt;
}