Hi Team
I have installed vis.min.js libraries somehow i am getting a lot of errors such as below. Please view and issue is on View.cshtml and did inspect the element, this is error im getting
“`
// Current issue
vis.js:20107 Uncaught Error: Property “start” missing in item [object Object]
at new o (vis.js:20107)
at n.<anonymous> (vis.js:18462)
at Array.forEach (<anonymous>)
at n._onUpdate (vis.js:18439)
at n.setItems (vis.js:18292)
at o.setItems (vis.js:40905)
at new o (vis.js:40826)
at Object.ChartVis [as success] (Index:91)
at fire (jquery-3.4.1.js:3291)
at Object.fireWith [as resolveWith] (jquery-3.4.1.js:3421)
// View code
@model CheckTimeLine.Models.SelectOption
@{
ViewBag.Title = “Home Page”;
}
<h2>TimeLine</h2>
<!– CSS –>
@section scripts{
<!– CSS –>
<script src=”/vis/vis.min.js”></script>
<link href=”/Content/vis.min.css” rel=”stylesheet”/>
<script type=”text/javascript”>
$(document).ready(function () {
$.ajax({
type: “GET”,
url: “GetAll”,
contentType: “application/json; charset=utf-8”,
dataType: “json”,
success: ChartVis,
error: OnError
});
function ChartVis(response) {
// 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(response);
// Configuration for the Timeline
var options = {};
// Create a Timeline
var timeline = new vis.Timeline(container, items, options);
}
function OnError(response) {
alert(“Error !”);
}
})
</script>
}
<div id=”visualization”></div>
your code here
```<i>
</i> public class HomeController : 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);
}<i>
</i>
``
``<i>
</i> function ChartVis(response) {
console.log(response);
// 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(response);
// Configuration for the Timeline
var options = {};
// Create a Timeline
var timeline = new vis.Timeline(container, items, options);
}<i>
</i>
``
``<i>
</i> function ChartVis(response) {
console.log('begin response');
console.log(response);
console.log('end response');
// 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(response);
// Configuration for the Timeline
var options = {};
// Create a Timeline
var timeline = new vis.Timeline(container, items, options);
}<i>
</i>
``
> Array(2)
> 0: {Incident: 1, Description: 'ShopFloor AMS Incident Report', Resources: 'Racs', Start_Date: '/Date(1631138400000)/', Timestamp: '/Date(1632369600000)/', …}
> 1: {Incident: 2, Description: 'ShopFloor AMS Incident report', Resources: 'Tracking Client', Start_Date: '/Date(1631138467000)/', Timestamp: '/Date(1631707200000)/', …}
> length: 2
> [[Prototype]]: Array(0)
``<i>
</i> function ChartVis(response) {
// convert reponse to format being required by vis.js:
const data = response.map((item) => {
// 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 };
});
console.log(data);
// 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);
}<i>
</i>
``
>I do see on your output you have correct order of day and date, what could i be missing?
``<i>
</i><!DOCTYPE html>
<html>
<head>
<title>Data Visualisation By vis.js</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis-network.min.css"
integrity="sha512-NJXM8vzWgDcBy9SCUTJXYnNO43sZV3pfLWWZMFTuCtEUIOcznk+AMpH6N3XruxavYfMeMmjrzDMEQ6psRh/6Hw=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.min.css"
integrity="sha512-8OVtKyemDe8Koi/74dnSJughhkwnzqq217zUtUumyvx0Z0kF6H0YYFobH2kEYjKMNq2xNQyN64dnleqecTSL0A=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.min.js"
integrity="sha512-XHDcSyqhOoO2ocB7sKOCJEkUjw/pQCJViP1ynpy+EGh/LggzrP6U/V3a++LQTnZT7sCQKeHRyWHfhN2afjXjCg=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis-timeline-graph2d.min.js"
integrity="sha512-e7wHjGSu73zD0szO6qaOwIlpco3utvaPyHzjRVsgU34Hw+yzlPXcSC27jlL3ddg0csFbdrx67QWS8pyVVMX10w=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<style>
</style>
</head>
<body>
<div id="visualization"></div>
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: "GET",
url: "thread758-visjs-webdev-3.json",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: ChartVis,
error: OnError
});
function ChartVis(response) {
// convert reponse to format required by vis.js:
const data = response.map((item) => {
// 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 };
});
console.log(data);
// 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 !");
}
});
</script>
</body>
</html><i>
</i>
`</CODE>
My JSON file:
<CODE>
`<i>
</i>[
{
"Incident": 1,
"Description": "ShopFloor AMS Incident Report",
"Resources": "Racs",
"Start_Date": "/Date(1631138400000)/",
"Timestamp": "/Date(1632369600000)/"
},
{
"Incident": 2,
"Description": "ShopFloor AMS Incident report",
"Resources": "Tracking Client",
"Start_Date": "/Date(1631138467000)/",
"Timestamp": "/Date(1631707200000)/"
}
]<i>
</i>
``
function ChartVis(response) {<br/>
// convert reponse to format being required by vis.js:<br/>
const data = response.map((item) => {<br/>
// parse Start_Date in order to get pure timestamp:<br/>
const parsed = item.Start_Date.match(//Date<ESC>(</ESC>(d+)<ESC>)</ESC>//);
<i> </i><CODE> // first attempt: create ISO date string, this was not necessary
<i> </i> // as vis.DataSet accepts the timestamp:
<i> </i> // const start = new Date(Number(parsed[1]));
<i> </i> // const startStr = start.toISOString();
<i> </i> // return record in format being required by timeline
<i> </i> return { id: item.Incident, start: Number(parsed[1]), content: item.Description };
<i> </i> });
<i> </i> console.log(data);
<i> </i> // DOM element where the Timeline will be attached
<i> </i> var container = document.getElementById('visualization');
<i> </i> var hours = document.getElementById("timeline");
<i> </i> var items = new vis.DataSet(data);
<i> </i> // sample entries
<i> </i> var s4Item = new vis.DataSet([{
<i> </i> id: 1,
<i> </i> content: 'ShopFlor AMS Incident Report',
<i> </i> start: '2021-09-15 03:00:00',
<i> </i> end: '2021-09-15 06:30:00'
<i> </i> }]);
<i> </i> // Create a DataSet (allows two way data-binding)
<i> </i>
<i> </i> // // Configuration for the Timeline
<i> </i> var options = {
<i> </i> // hide weekends - use any weekend and repeat weekly
<i> </i> hiddenDates: [{
<i> </i> start: '2021-08-04 00:00:00',
<i> </i> end: '2021-08-06 00:00:00',
<i> </i> repeat: 'weekly'
<i> </i> },
<i> </i> // hide outside of 9am to 5pm - use any 2 days and repeat daily
<i> </i> {
<i> </i> start: '2021-08-04 17:00:00',
<i> </i> end: '2021-08-05 09:00:00',
<i> </i> repeat: 'daily'
<i> </i> }
<i> </i> ],
<i> </i> // start and end of timeline
<i> </i> start: '2021-09-01',
<i> </i> end: '2021-09-30',
<i> </i> height: '140px',
<i> </i> editable: false
<i> </i> };
<i> </i> // // Create a Timeline
<i> </i> var timeline = new vis.Timeline(container, items, options);
<i> </i> }
>I want to implement total hours worked on a given task to be display on UI
start
`end
</C> additionally, if duration is available you can easily calculate <C>
end
</C> by adding duration to <C>
start
`Timestamp
```<i>
</i> function ChartVis(response) {
// get timestamp from string:
function getTime(timeStr) {
const parsed = timeStr.match(//Date((d+))//);
return Number(parsed[1]);
}
// convert reponse to format required by vis.js:
const data = response.map((item) => {
// return record in format being required by timeline
return {
id: item.Incident,
start: getTime(item.Start_Date),
end: getTime(item.Timestamp),
content: item.Description
};
});
console.log(data);
// 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);
}<i>
</i>
``
>my issue is on the calculation of hours, so it can be shown. total hours spend on activity
``<i>
</i> function ChartVis(response) {
// get timestamp from string:
function getTime(timeStr) {
const parsed = timeStr.match(//Date((d+))//);
return Number(parsed[1]);
}
// get minutes from time related to start of day:
function getMinutes(timeStamp) {
dat = new Date(timeStamp);
return dat.getHours() * 60 + dat.getMinutes();
}
// calculate diff in days according to
// https://stackoverflow.com/questions/3224834/get-difference-between-2-dates-in-javascript
const _MS_PER_DAY = 1000 * 60 * 60 * 24;
// a and b are javascript Date objects
function dateDiffInDays(a, b) {
// Discard the time and time-zone information.
const utc1 = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate());
const utc2 = Date.UTC(b.getFullYear(), b.getMonth(), b.getDate());
return Math.floor((utc2 - utc1) / _MS_PER_DAY);
}
// get minutes for business times:
for (key in businessTime) {
const splitted = businessTime[key].split(':');
businessTime[key + 'Minutes'] = parseInt(splitted[0]) * 60 + parseInt(splitted[1]);
}
businessTime.minutesOneDay = businessTime.endMinutes - businessTime.startMinutes;
console.log(businessTime);
// calculate amount of time
const data = response.map((item) => {
const
startTimestamp = getTime(item.Start_Date),
endTimestamp = getTime(item.Timestamp);
// from here we are using minutes related to the start of the day
let
startMinutes = getMinutes(startTimestamp),
endMinutes = getMinutes(endTimestamp);
if (startMinutes < businessTime.startMinutes) {
startMinutes = businessTime.startMinutes;
}
if (endMinutes > businessTime.endMinutes) {
endMinutes = businessTime.endMinutes;
}
// calculate total time the task took
const
// calculate amount on first day:
amountFirstDay = businessTime.endMinutes - startMinutes,
// calculate amount on last day:
amountLastDay = endMinutes - businessTime.startMinutes;
// get difference in days between first and last day:
diffDays = dateDiffInDays(new Date(startTimestamp), new Date(endTimestamp));
let totalMinutes;
// did the task take more than one day?
if (diffDays > 0) {
totalMinutes = amountFirstDay + diffDays * businessTime.minutesOneDay + amountLastDay;
} else {
// task took one day only:
totalMinutes = endMinutes - startMinutes;
}
console.log(totalMinutes);
// return record in format being required by timeline
return {
id: item.Incident,
start: startTimestamp,
end: endTimestamp,
content: item.Description + '<br>Took ' + totalMinutes + ' minutes'
};
});
console.log(data);
// 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);
}<i>
</i>
``
``<i>
</i>Index:105 Uncaught ReferenceError: businessTime is not defined
at Object.ChartVis [as success] (Index:105)
at fire (jquery-3.4.1.js:3291)
at Object.fireWith [as resolveWith] (jquery-3.4.1.js:3421)
at done (jquery-3.4.1.js:9533)
at XMLHttpRequest.<anonymous> (jquery-3.4.1.js:9785)<i>
</i>
``
``<i>
</i> const businessTime = {
start: '8:00',
end: '16:00'
}<i>
</i>
``
``<i>
</i> <script type="text/javascript">
$(document).ready(function () {
const businessTime = {
start: '8:00',
end: '16:00'
}
$.ajax({
type: "GET",
url: "thread758-visjs-webdev-3.json",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: ChartVis,
error: OnError
});
function ChartVis(response) {
// and so on<i>
</i>
``
``<i>
</i> function ChartVis(response) {
// get timestamp from string:
function getTime(timeStr) {
const parsed = timeStr.match(//Date((d+))//);
return Number(parsed[1]);
}
// get minutes from time related to start of day:
function getMinutes(timeStamp) {
dat = new Date(timeStamp);
return dat.getHours() * 60 + dat.getMinutes();
}
// calculate diff in days according to
// https://stackoverflow.com/questions/3224834/get-difference-between-2-dates-in-javascript
const _MS_PER_DAY = 1000 * 60 * 60 * 24;
// a and b are javascript Date objects
function dateDiffInDays(a, b) {
// Discard the time and time-zone information.
const utc1 = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate());
const utc2 = Date.UTC(b.getFullYear(), b.getMonth(), b.getDate());
return Math.floor((utc2 - utc1) / _MS_PER_DAY);
}
// get minutes for business times:
for (key in businessTime) {
const splitted = businessTime[key].split(':');
businessTime[key + 'Minutes'] = parseInt(splitted[0]) * 60 + parseInt(splitted[1]);
}
businessTime.minutesOneDay = businessTime.endMinutes - businessTime.startMinutes;
console.log(businessTime);
// calculate amount of time
const data = response.map((item) => {
const
startTimestamp = getTime(item.Start_Date),
endTimestamp = getTime(item.Timestamp);
// from here we are using minutes related to the start of the day
let
startMinutes = getMinutes(startTimestamp),
endMinutes = getMinutes(endTimestamp);
if (startMinutes < businessTime.startMinutes) {
startMinutes = businessTime.startMinutes;
}
if (endMinutes > businessTime.endMinutes) {
endMinutes = businessTime.endMinutes;
}
// calculate total time the task took
const
// calculate amount on first day:
amountFirstDay = businessTime.endMinutes - startMinutes,
// calculate amount on last day:
amountLastDay = endMinutes - businessTime.startMinutes;
// get difference in days between first and last day:
diffDays = dateDiffInDays(new Date(startTimestamp), new Date(endTimestamp));
let totalMinutes;
// did the task take more than one day?
if (diffDays > 0) {
totalMinutes = amountFirstDay + diffDays * businessTime.minutesOneDay + amountLastDay;
} else {
// task took one day only:
totalMinutes = endMinutes - startMinutes;
}
console.log(totalMinutes);
// convert amount of time to hours:minutes
let min = totalMinutes % 60;
if (min < 10) min = '0' + min;
const hours = Math.floor(totalMinutes / 60),
totalHours = '' + hours + ':' + min;
console.log(totalHours);
// return record in format being required by timeline
return {
id: item.Incident,
start: startTimestamp,
end: endTimestamp,
content: item.Description + '<br>Took ' + totalHours + ' hours'
};
});
console.log(data);
// 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);
}<i>
</i>
``
``<i>
</i> // did the task take more than one day?
if (diffDays > 0) {
totalMinutes = amountFirstDay + (diffDays - 1) * businessTime.minutesOneDay + amountLastDay;
} else {
// task took one day only:
totalMinutes = endMinutes - startMinutes;
}<i>
</i>
``
>i have a question in mind, is it possible that total hours worked on be shown be day(shift)?
e.g Wilson took 2 hours on Management report, date 12 September 2021 and time 09:00-11:00am/pm
This is the only thing i need based on what we have if make sense.
0.1.9 — BETA 4.27