Hi muhammad12,
Please refer below updated code.
DataBase
I have created GoogleTimeline table.
CREATE TABLE GoogleTimeline
(
ActionID INT NOT NULL,
eventname VARCHAR(100),
starttime VARCHAR(100),
endtime VARCHAR(100),
DeptName VARCHAR(100)
)
I have insert some records.
INSERT INTO GoogleTimeline (ActionID, eventname,starttime,endtime,DeptName) VALUES(1, 'jan', '10:40', '10:45', 'Airside')
INSERT INTO GoogleTimeline (ActionID, eventname,starttime,endtime,DeptName) VALUES(6, 'jan', '9:00', '9:30', 'Catering')
INSERT INTO GoogleTimeline (ActionID, eventname,starttime,endtime,DeptName) VALUES(9, 'jan', '10:00', '10:32', 'FOCC')
INSERT INTO GoogleTimeline (ActionID, eventname,starttime,endtime,DeptName) VALUES(10, 'Jan', '6:00', '6:15', 'Flight Services')
INSERT INTO GoogleTimeline (ActionID, eventname,starttime,endtime,DeptName) VALUES(2, 'feb', '21:00', '22:10', 'Catering')
INSERT INTO GoogleTimeline (ActionID, eventname,starttime,endtime,DeptName) VALUES(7, 'feb', '7:00', '7:40', 'FOCC')
INSERT INTO GoogleTimeline (ActionID, eventname,starttime,endtime,DeptName) VALUES(8, 'feb', '8:00', '8:25', 'Airside')
INSERT INTO GoogleTimeline (ActionID, eventname,starttime,endtime,DeptName) VALUES(3, 'mar', '12:00', '12:10', 'Airside')
INSERT INTO GoogleTimeline (ActionID, eventname,starttime,endtime,DeptName) VALUES(11, 'mar', '15:00', '15:30', 'FOCC')
INSERT INTO GoogleTimeline (ActionID, eventname,starttime,endtime,DeptName) VALUES(12, 'mar', '9:00', '9:20', 'Flight Services')
INSERT INTO GoogleTimeline (ActionID, eventname,starttime,endtime,DeptName) VALUES(4, 'Apr', '01:00', '01:10', 'FOCC')
INSERT INTO GoogleTimeline (ActionID, eventname,starttime,endtime,DeptName) VALUES(5, 'may', '0:000', '00:20', 'Catering')
HTML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CS.aspx.cs" Inherits="CS" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style>
/* Style to center the input form */
#registration-form-container { display: flex; justify-content: center; align-items: flex-start; /* Align form to the top */ overflow: hidden; margin-top: 0px; /* Adjust top margin as needed */ }
#registration-form { display: inline-block; /* Ensure it only takes the necessary width */ padding: 20px; border: 1px solid #ccc; background-color: #f2f2f2; border-radius: 8px; overflow: hidden; font-family: 'Sofia Sans Condensed', sans-serif; /* Use Sofia Sans Condensed font */ }
/* Style to make the "Clockify report!" title more prominent */
legend { font-weight: bold; font-size: 20px; margin-bottom: 20px; font-family: 'Sofia Sans Condensed', sans-serif; /* Use Sofia Sans Condensed font */ }
/* Style to place input elements in one row */
.input-group { display: inline-block; margin-right: 10px; /* Adjust as needed */ }
/* Style to adjust the width of input elements */
.input { width: 150px; /* Adjust as needed */ padding: 5px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; font-family: 'Sofia Sans Condensed', sans-serif; /* Use Sofia Sans Condensed font */ }
/* Style for labels */
.label { display: block; margin-bottom: 5px; color: black; font-size: 14px; font-weight: bold; font-family: 'Sofia Sans Condensed', sans-serif; /* Use Sofia Sans Condensed font */ }
/* Style for buttons */
.btn { background-color: #4CAF50; color: white; padding: 10px 20px; border: none; font-weight: bold; border-radius: 4px; cursor: pointer; font-family: 'Sofia Sans Condensed', sans-serif; /* Use Sofia Sans Condensed font */ }
/* Hover effect for buttons */
.btn:hover { background-color: #45a049; }
/* Style to make sure the timeline adjusts according to device width */
#departmentChartsContainer { white-space: nowrap; margin-top: 20px; font-family: 'Sofia Sans Condensed', sans-serif; /* Use Sofia Sans Condensed font */ overflow-x: hidden; /* Hide horizontal scrollbar */ overflow-y: hidden; width: 100%; /* Fix the width of the container */ display: block; }
.sentence { display: flex; align-items: center; margin-top: 10px; }
.sentence .label { margin-right: 5px; }
</style>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.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: 'date', id: 'Start' });
dataTable.addColumn({ type: 'date', id: 'End' });
for (var departmentName in data) {
if (data.hasOwnProperty(departmentName)) {
data[departmentName].forEach(function (event) {
var start = new Date('2000/01/01 ' + event[2]); // Assuming the date component is irrelevant
var end = new Date('2000/01/01 ' + event[3]); // Assuming the date component is irrelevant
dataTable.addRows([[departmentName, event[1], start, end]]);
});
}
}
var options = {
timeline: {
groupByRowLabel: false,
colorByRowLabel: true, // Display each event on a new line
rowLabelStyle: { fontName: 'Sofia Sans Condensed', fontSize: 14, color: '#000000', bold: true },
barLabelStyle: { fontSize: 14, bold: true, fontName: 'Sofia Sans Condensed', color: '#000000 ' },
avoidOverlappingGridLines: true
},
alternatingRowStyle: false,
backgroundColor: '#ffd',
height: 2000
};
chart.draw(dataTable, options);
}
$(function () {
$("#btnView").click(function () {
var flightNo = $("#flightNo").val();
var flightDate = $("#flightDate").val();
var flightType = $("#flightType").val();
$.ajax({
type: "POST",
url: "CS.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>
</head>
<body>
<form id="form1" runat="server">
<div id="registration-form-container">
<div id="registration-form">
<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 Date " 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 class="row sentence" style="display: none;">
<asp:Label ID="Label4" runat="server" Text="This Flight Started From: " CssClass="label" Style="color: red;"></asp:Label>
<asp:Label ID="StartTime" runat="server" Text="10:00" CssClass="label" Style="font-weight: bold;"></asp:Label>
<asp:Label ID="Label5" runat="server" Text=" And Ended at: " CssClass="label" Style="color: red;"></asp:Label>
<asp:Label ID="EndTime" runat="server" Text="12:00" CssClass="label" Style="font-weight: bold;"></asp:Label>
</div>
</div>
</div>
<!-- Container for department Gantt charts -->
<div id="departmentChartsContainer"></div>
</form>
</body>
</html>
Code
[WebMethod]
public static Dictionary<string, List<object[]>> GetChartData(string flightNo, string flightDate, string flightType)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
string query = "SELECT ActionID, eventname, starttime, endtime, DeptName FROM GoogleTimeline";
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlDataAdapter sda = new SqlDataAdapter(query, con))
{
using (DataTable dt = new DataTable())
{
con.Open();
sda.Fill(dt);
Dictionary<string, List<object[]>> departmentChartData = new Dictionary<string, List<object[]>>();
foreach (DataRow row in dt.Rows)
{
string departmentName = row["DeptName"].ToString();
if (!departmentChartData.ContainsKey(departmentName))
{
departmentChartData[departmentName] = new List<object[]>();
}
departmentChartData[departmentName].Add(new object[] {
row["eventname"],
row["eventname"],
row["starttime"].ToString(),
row["endtime"].ToString()
});
}
return departmentChartData;
}
}
}
}
Screenshot