Click here to Skip to main content
15,941,649 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
Hi team

I dont know how to calculate total hours for user worked on a incident report, currently need some help around this logic. There are no errors and worked below does work and using to pull data back from table records. Should i need to have a unique record for total hours has datatype like datetime?

I am using visjs framework for timeline and here is the link below for documentation.
timeline - vis.js - A dynamic, browser based visualization library.[^]

What I have tried:

// Model
public class SelectOption
      public int Incident { get; set; }

      public string Description { get; set; }

      public string Resources { get; set; }

      public DateTime Start_Date { get; set; }

      public DateTime Timestamp { get; set; }

// Should i need to have a data type here for total hours?

// controller
  public TimeLineApplicationDBEntities2 _context = new TimeLineApplicationDBEntities2();
        public ActionResult Index()
            return View();

        public JsonResult GetAll()
            var data = _context.Application_CheckList.ToList();
            return Json(data, JsonRequestBehavior.AllowGet);

// View.cshtml
<pre>@section scripts{

    <!-- CSS -->
    <script src="/vis/vis.js"></script>
    <link href="/Content/vis.min.css" rel="stylesheet" />

    <script type="text/javascript">

        $(document).ready(function () {

                type: "GET",
                url: "GetAll",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: ChartVis,
                error: OnError


            function ChartVis(response) {
                // convert reponse to format being required by vis.js:
                const data = => {
                    // parse Start_Date in order to get pure timestamp:
                    const parsed = item.Start_Date.match(/\/Date\((\d+)\)\//);

                    // first attempt: create ISO date string, this was not necessary 
                    // as vis.DataSet accepts the timestamp:
                    // const start = new Date(Number(parsed[1]));
                    // const startStr = start.toISOString();

                    // return record in format being required by timeline
                    return { id: item.Incident, start: Number(parsed[1]), content: item.Description };
                // DOM element where the Timeline will be attached
                var container = document.getElementById('visualization');

                // Create a DataSet (allows two way data-binding)
                var items = new vis.DataSet(data);

                // // Configuration for the Timeline
                var options = {};

                // // Create a Timeline
                var timeline = new vis.Timeline(container, items, options);

            function OnError(response) {
                alert("Error !");



<div id="visualization"></div>

Updated 25-Oct-21 19:01pm
[no name] 26-Oct-21 15:01pm    
Add a "getter" to SelectOption that returns hours ... assuming there's some sort of relationship between Start_Date, Timestamp and what you need.
Tgcobza Mkontwana 12-Nov-21 0:34am    
@Gerry Schmitz please share some example, will amend once shown and understand

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900