Refer below sample.
HTML
<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>
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: 'Department' });
dataTable.addColumn({ type: 'string', id: 'Event' });
dataTable.addColumn({ type: 'date', id: 'Start' });
dataTable.addColumn({ type: 'date', id: 'End' });
for (var i = 0; i < data.length; i++) {
dataTable.addRows([[data[i].Role, data[i].Name, new Date(data[i].starttime), new Date(data[i].endtime)]]);
}
var options = {
timeline: {
//groupByRowLabel: false // Display each event on a new line
},
height: 700,
};
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>
<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"></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>
Namespaces
using System.Data;
using System.Web.Services;
Code
[WebMethod]
public static List<ChartData> GetChartData(string flightNo, string flightDate, string flightType)
{
List<ChartData> departmentChartData = new List<ChartData>();
DataTable dt = new DataTable();
dt.Columns.Add("ActionID");
dt.Columns.Add("DeptName");
dt.Columns.Add("eventname");
dt.Columns.Add("starttime");
dt.Columns.Add("endtime");
dt.Rows.Add(1, "Caltering", "events bars1", new DateTime(2024, 2, 6), new DateTime(2024, 2, 10));
dt.Rows.Add(2, "Caltering", "events bars2", new DateTime(2024, 2, 7), new DateTime(2024, 2, 11));
dt.Rows.Add(3, "Caltering", "events bars3", new DateTime(2024, 2, 6), new DateTime(2024, 2, 13));
dt.Rows.Add(4, "Airside", "events bars1", new DateTime(2024, 2, 6), new DateTime(2024, 2, 10));
dt.Rows.Add(5, "Airside", "2", new DateTime(2024, 2, 7), new DateTime(2024, 2, 11));
dt.Rows.Add(6, "Focc", "events bars4", new DateTime(2024, 2, 6), new DateTime(2024, 2, 13));
dt.DefaultView.Sort = "DeptName";
dt = dt.DefaultView.ToTable();
foreach (DataRow dr in dt.Rows)
{
departmentChartData.Add(new ChartData
{
Role = dr["DeptName"].ToString(),
Name = dr["eventname"].ToString() + " - " + dr["ActionID"].ToString(),
starttime = dr["starttime"].ToString(),
endtime = dr["endtime"].ToString()
});
}
return departmentChartData;
}
public class ChartData
{
public string Role { get; set; }
public string Name { get; set; }
public string starttime { get; set; }
public string endtime { get; set; }
}
Screenshot