Google Gantt Chart Shows Wrong Year
I have started using Gantt chart which is recently launched by Google which seems great for tasks tracking via chart. I have created 4 tasks and chart loads fine but it shows wrong
Solution 1:
month numbers are zero-based in JavaScript
so Dec, 1 2015 would be --> new Date(2015, 11, 01)
instead the 12
pushes the date to Jan 1, 2016
see following snippets...
Date Test
console.log(newDate(2015, 11, 01));
console.log(newDate(2015, 12, 01));
Chart Test
if the range should be Aug - Dec, then reduce each month # by 1
google.charts.load('current', {'packages':['gantt']});
google.charts.setOnLoadCallback(drawChart);
functiondaysToMilliseconds(days) {
return days * 24 * 60 * 60 * 1000;
}
functiondrawChart() {
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([
['Design', 'Design and analysis',
newDate(2015, 7, 1), newDate(2015, 7, 15), null, 25, null],
['Development', 'Develop the product',
newDate(2015, 7, 16), newDate(2015, 9, 31), null, 20, null],
['Testing', 'Product testing',
newDate(2015, 10, 01), newDate(2015, 10, 30), null, 10, null],
['Release', 'Release the product',
newDate(2015, 11, 01), newDate(2015, 11, 20), null, 0, null],
]);
var options = {
height: 275
};
var chart = new google.visualization.Gantt(document.getElementById('chart_div'));
chart.draw(data, options);
}
<scripttype="text/javascript"src="https://www.gstatic.com/charts/loader.js"></script><divid="chart_div"></div>
Post a Comment for "Google Gantt Chart Shows Wrong Year"