I have a Gantt Chart which is used to show the Project Timeline. I am using Google Charts to display the Gantt Chart.
Below is the VF page:
<apex:page standardController="Project__c">
<apex:form >
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['gantt']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Task ID');
data.addColumn('string', 'Task Name');
data.addColumn('date', 'Start Date');
data.addColumn('date', 'End Date');
data.addColumn('number', 'Duration');
data.addColumn('number', 'Percent Complete');
data.addColumn('string', 'Dependencies');
data.addRows([
['Research', 'Find sources',
new Date("{!Project__c.GLI_Planned_Date__c}"), new Date("{!Project__c.GLI_Actual_Date__c}"), null, 100, null],
['Write', 'Write paper',
new Date("{!Project__c.REG_Planned_Date__c}"), new Date("{!Project__c.REG_Actual_Date__c}"), daysToMilliseconds(3), 25, 'null'],
['Cite', 'Create bibliography',
new Date("{!Project__c.UAT_Planned_Date__c}"), new Date("{!Project__c.UAT_Actual_Date__c}"), daysToMilliseconds(1), 20, 'null'],
['Complete', 'Hand in paper',
new Date("{!Project__c.STP_Planned_Date__c}"), new Date("{!Project__c.STP_Actual_Date__c}"), daysToMilliseconds(1), 0, 'null'],
['Outline', 'Outline paper',
new Date("{!Project__c.ARC_Planned_Date__c}"), new Date("{!Project__c.ARC_Actual_Date__c}"), daysToMilliseconds(1), 100, 'null']
]);
var options = {
height: 400,
gantt: {
trackHeight: 30
}
};
var chart = new google.visualization.Gantt(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div"></div>
</body>
</html>
</apex:form>
</apex:page>
Now, the issue here is that, for few records, the date fields are null. Due to that, I am seeing the error as
Cannot read property 'datefield' of undefined
Is there any way that I can display some custom banner like "Required date values are not available" instead of the above error in case of missing date values?
Please suggest
Required Dates are missing
instead of hiding the error?