Hi muhammad12,
Refer below sample code.
HTML
<div id="registration-form">
<div class='fieldset'>
<legend>Clockify report!</legend>
<div class="row">
<div class="input-group">
<asp:Label ID="Label1" runat="server" Text="Flight No" CssClass="label"></asp:Label>
<asp:TextBox ID="flightNo" runat="server" CssClass="input"></asp:TextBox>
</div>
<div class="input-group">
<asp:Label ID="Label2" runat="server" Text="Flight No" CssClass="label"></asp:Label>
<asp:TextBox ID="flightDate" runat="server" CssClass="input" type="date"></asp:TextBox>
</div>
<div class="input-group">
<asp:Label ID="Label3" runat="server" Text="Flight Type" CssClass="label"></asp:Label>
<asp:DropDownList ID="flightType" runat="server" CssClass="input" Style="color: Black; font-size: 20px;">
<asp:ListItem Text="Arrival" />
<asp:ListItem Text="Departure" />
</asp:DropDownList>
</div>
<!-- Add other input elements here -->
<div class="input-group">
<asp:Button ID="btnView" runat="server" Text="Submit" class="btn" />
</div>
</div>
</div>
</div>
<!-- Container for department Gantt charts -->
<div id="departmentChartsContainer"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load("current", { packages: ["timeline"] });
function drawChart(data, chartDivId) {
var container = document.getElementById(chartDivId);
var chart = new google.visualization.Timeline(container);
var dataTable = new google.visualization.DataTable();
dataTable.addColumn({ type: 'string', id: 'Role' });
dataTable.addColumn({ type: 'string', id: 'Name' });
dataTable.addColumn({ type: 'datetime', id: 'Start' });
dataTable.addColumn({ type: 'datetime', id: 'End' });
for (var i = 0; i < data.length; i++) {
var dept = data[i].DeptName;
var event = data[i].EventName;
var startDate = new Date(data[i].StartDate);
var endDate = new Date(data[i].EndDate);
dataTable.addRows([[dept, event, startDate, endDate]]);
}
var options = {
timeline: {},
height: 500,
};
chart.draw(dataTable, options);
}
$(document).ready(function () {
$("#btnView").click(function () {
var flightNo = $("#flightNo").val();
var flightDate = $("#flightDate").val();
var flightType = $("#flightType").val();
$.ajax({
type: "POST",
url: "Default.aspx/GetChartData",
data: JSON.stringify({ flightNo: flightNo, flightDate: flightDate, flightType: flightType }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
drawChart(response.d, "departmentChartsContainer");
},
error: function (response) {
alert(response.responseText);
}
});
return false;
});
});
</script>
Code
[WebMethod]
public static List<MapData> GetChartData(string flightNo, string flightDate, string flightType)
{
List<MapData> mapDatas = new List<MapData>();
mapDatas.Add(new MapData { DeptName = "Traffic", EventName = "Jan", StartDate = "2024/02/20 11:02:00 am", EndDate = "2024/02/20 11:03:00 am" });
mapDatas.Add(new MapData { DeptName = "Traffic", EventName = "Feb", StartDate = "2024/02/20 11:03:00 am", EndDate = "2024/02/20 11:04:00 am" });
mapDatas.Add(new MapData { DeptName = "Traffic", EventName = "Mar", StartDate = "2024/02/20 11:04:00 am", EndDate = "2024/02/20 11:05:00 am" });
mapDatas.Add(new MapData { DeptName = "Traffic", EventName = "Apr", StartDate = "2024/02/20 11:06:00 am", EndDate = "2024/02/20 11:38:00 am" });
mapDatas.Add(new MapData { DeptName = "Airside", EventName = "Jan", StartDate = "2024/02/20 11:02:00 am", EndDate = "2024/02/20 11:03:00 am" });
mapDatas.Add(new MapData { DeptName = "Airside", EventName = "Feb", StartDate = "2024/02/20 11:06:00 am", EndDate = "2024/02/20 11:38:00 am" });
mapDatas.Add(new MapData { DeptName = "Airside", EventName = "Mar", StartDate = "2024/02/20 11:05:00 am", EndDate = "2024/02/20 11:30:00 am" });
mapDatas.Add(new MapData { DeptName = "Airside", EventName = "Apr", StartDate = "2024/02/20 11:25:00 am", EndDate = "2024/02/20 11:40:00 am" });
mapDatas.Add(new MapData { DeptName = "Catering", EventName = "Jan", StartDate = "2024/02/20 11:02:00 am", EndDate = "2024/02/20 11:03:00 am" });
mapDatas.Add(new MapData { DeptName = "Catering", EventName = "Feb", StartDate = "2024/02/20 11:44:00 am", EndDate = "2024/02/20 11:46:00 am" });
mapDatas.Add(new MapData { DeptName = "Catering", EventName = "Mar", StartDate = "2024/02/20 11:46:00 am", EndDate = "2024/02/20 11:47:00 am" });
mapDatas.Add(new MapData { DeptName = "Catering", EventName = "Apr", StartDate = "2024/02/20 11:47:00 am", EndDate = "2024/02/20 12:00:00 pm" });
return mapDatas;
}
public class MapData
{
public string DeptName { get; set; }
public string EventName { get; set; }
public string StartDate { get; set; }
public string EndDate { get; set; }
}