# Gantt Chart - Date Issues

**URL:** <https://forum.inductiveautomation.com/t/gantt-chart-date-issues/35223>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [June 1, 2020, 5:59pm UTC](https://forum.inductiveautomation.com/t/gantt-chart-date-issues/35223 "2020-06-01T17:59:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![MikeAMCO](https://avatars.discourse-cdn.com/v4/letter/m/df705f/32.png) [@MikeAMCO](https://forum.inductiveautomation.com/u/MikeAMCO)\
**Post date:** [June 1, 2020, 5:59pm UTC](https://forum.inductiveautomation.com/t/gantt-chart-date-issues/35223/1 "2020-06-01T17:59:54Z")

</div>

Is there a way to directly right a date value to the Gantt Chart´s “Start Time” and “End Time”? I am looking for something that will work using a process such as:

**date string (from popup Calendar component) \> parse \> data calculation \> write to Gantt Chart**

I am having issues with the Gantt Chart component. I keep getting an error message when I try to set the Gantt Chart dataset to a built data set. The code is below.

```auto
# reads task data from root´s Custom Property 'taskData' 
taskData = event.source.parent.taskData

# Builds ganttData dataset with no row data
headers = ['Task Name', 'Start Date', 'End Date', 'Percentage Done']
data =[]
ganttData = system.dataset.toDataSet(headers, data)

# sets percentage and startDate
percentage = 0
startDate = event.source.parent.getComponent('calStartDate').date
	
rows = taskData.getRowCount()
for row in range(rows):
	rowData =[]
	taskName = taskData.getValueAt(row,'task_name')
	weeks = taskData.getValueAt(row,'task_week')
	if row == 0:
		startDate = system.date.parse(startDate, "yyyy-MM-dd HH:mm:ss")
		endDate = system.date.parse(system.date.addWeeks(startDate, weeks), "yyyy-MM-dd HH:mm:ss")

	else:
		prevEndDate = system.date.parse(ganttData.getValueAt(row-1,'End Date'), "yyyy-MM-dd HH:mm:ss")
		startDate = system.date.parse(system.date.addDays(prevEndDate, 1), "yyyy-MM-dd HH:mm:ss")
		endDate = system.date.parse(system.date.addWeeks(startDate, weeks), "yyyy-MM-dd HH:mm:ss")

	rowData.append(taskName)
	rowData.append(startDate)
	rowData.append(endDate)
	rowData.append(percentage)
	
	ganttData = system.dataset.addRow(ganttData, rowData)
		
	#system.db.runPrepUpdate("INSERT INTO temp_timelines (taskName, startDate, endDate, percentage) VALUES (?,?,?,?)", [taskName, startDate, endDate, percentage])

#chartData = system.db.runQuery("SELECT taskName AS 'Task Name', startDate AS 'Start Date', endDate AS 'End Date', percentage AS 'Percentage' FROM temp_timelines")

event.source.parent.getComponent('Gantt Chart').data = ganttData

```

I have tried many different ways to parse the string - python and Java methods, but I admit to being a rookie so I could have easily overlooked some detail.

Having said that, I explored another method that did work, but via a circuitous route. I first INSERT the row data into to a MySQL table with DATETIME columns and then SELECT this data assigning it to the Gantt Chart table property. While this process works I do not like it as I am trying to reduce DB transactions when possible.

![working](https://us1.discourse-cdn.com/inductiveautomation/original/2X/a/a854775c4e742f7b3613da87aa441c7653486868.png)

```auto
system.db.runPrepUpdate("DELETE FROM temp_timelines WHERE taskName LIKE ?", ['%'])

# reads task data from root´s Custom Property 'taskData' 
taskData = event.source.parent.taskData

# Builds ganttData dataset with no row data
headers = ['Task Name', 'Start Date', 'End Date', 'Percentage Done']
data =[]
ganttData = system.dataset.toDataSet(headers, data)

# sets percentage and startDate
percentage = 0
startDate = event.source.parent.getComponent('calStartDate').date
	
rows = taskData.getRowCount()
for row in range(rows):
	rowData =[]
	taskName = taskData.getValueAt(row,'task_name')
	weeks = taskData.getValueAt(row,'task_week')
	if row == 0:
		startDate = system.date.parse(startDate, "yyyy-MM-dd HH:mm:ss")
		endDate = system.date.parse(system.date.addWeeks(startDate, weeks), "yyyy-MM-dd HH:mm:ss")

	else:
		prevEndDate = system.date.parse(ganttData.getValueAt(row-1,'End Date'), "yyyy-MM-dd HH:mm:ss")
		startDate = system.date.parse(system.date.addDays(prevEndDate, 1), "yyyy-MM-dd HH:mm:ss")
		endDate = system.date.parse(system.date.addWeeks(startDate, weeks), "yyyy-MM-dd HH:mm:ss")

	rowData.append(taskName)
	rowData.append(startDate)
	rowData.append(endDate)
	rowData.append(percentage)
	
	ganttData = system.dataset.addRow(ganttData, rowData)
		
	system.db.runPrepUpdate("INSERT INTO temp_timelines (taskName, startDate, endDate, percentage) VALUES (?,?,?,?)", [taskName, startDate, endDate, percentage])

chartData = system.db.runQuery("SELECT taskName AS 'Task Name', startDate AS 'Start Date', endDate AS 'End Date', percentage AS 'Percentage' FROM temp_timelines")

event.source.parent.getComponent('Gantt Chart').data = chartData

```

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [June 1, 2020, 10:27pm UTC](https://forum.inductiveautomation.com/t/gantt-chart-date-issues/35223/2 "2020-06-01T22:27:15Z")

</div>

Why are you parsing the date in the first place?

---

<div class="post-metadata">

**Author:** ![MikeAMCO](https://avatars.discourse-cdn.com/v4/letter/m/df705f/32.png) [@MikeAMCO](https://forum.inductiveautomation.com/u/MikeAMCO)\
**Post date:** [June 1, 2020, 10:49pm UTC](https://forum.inductiveautomation.com/t/gantt-chart-date-issues/35223/3 "2020-06-01T22:49:20Z")

</div>

It is my understanding the functions like system.date.addDays need to be a Date datatype to work. Also, the Gantt Chart component requires Date for Start Date and End Date.

Since, the pop calendar returns a string, I assumed that this data needs to be converted and Parse is used for that function.

Am I missing something.

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [June 1, 2020, 10:54pm UTC](https://forum.inductiveautomation.com/t/gantt-chart-date-issues/35223/4 "2020-06-01T22:54:18Z")

</div>

The popup calendar returns a date.

```auto
print event.source.parent.getComponent('Popup Calendar').date
print type(event.source.parent.getComponent('Popup Calendar').date)

Mon Jun 01 15:52:33 PDT 2020
<type 'java.util.Date'>

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 1, 2020, 11:00pm UTC](https://forum.inductiveautomation.com/t/gantt-chart-date-issues/35223/5 "2020-06-01T23:00:51Z")

</div>

I haven’t analyzed all of your code, but one flaw jumped out at me: you are constructing a dataset with no rows, then adding rows to it one by one. Don’t do this. Column datatypes are established when a dataset is created–with no data, I believe all columns are string. So when you add rows, the data in those rows has to be coerced to match the established column types, breaking your expectations.

Append your `rowData` to a plain python list, `rows`, perhaps. Then, after the loop, construct the gantt dataset in one call.

---

<div class="post-metadata">

**Author:** ![MikeAMCO](https://avatars.discourse-cdn.com/v4/letter/m/df705f/32.png) [@MikeAMCO](https://forum.inductiveautomation.com/u/MikeAMCO)\
**Post date:** [June 2, 2020, 12:48am UTC](https://forum.inductiveautomation.com/t/gantt-chart-date-issues/35223/6 "2020-06-02T00:48:25Z")

</div>

Thank you Phil,

Your response got me headed in the right direction. It now works. As you said, the way I was creating the data caused all columns to be strings. So when I wrote the date to the Start Date or End Date column it was coerced into a string thereby causing the error.

Here is the code for anyone who might be interested.

```auto
# reads task data from root´s Custom Property 'taskData' 
taskData = event.source.parent.taskData

# sets percentage and startDate
percentage = 0
startDate = event.source.parent.getComponent('calStartDate').date

rowData =[]	
rows = taskData.getRowCount()

for row in range(rows):

	taskName = taskData.getValueAt(row,'task_name')
	weeks = taskData.getValueAt(row,'task_week')
	
	if row == 0:
		endDate = system.date.addWeeks(startDate, weeks)
	
	else:
		prevEndDate = rowData[row-1][2]
		startDate = system.date.addDays(prevEndDate, 1)
		endDate = system.date.addWeeks(startDate,weeks)

	rowData.append([taskName, startDate, endDate, percentage])

# Builds ganttData dataset with no row data
headers = ['Task Name', 'Start Date', 'End Date', 'Percentage Done']

ganttData = system.dataset.toDataSet(headers, rowData)
event.source.parent.getComponent('Table').data = ganttData
event.source.parent.getComponent('Gantt Chart').data = ganttData

```
