Google甘特图显示错误的一年

编程入门 行业动态 更新时间:2024-10-23 17:39:42
本文介绍了Google甘特图显示错误的一年的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经创建了4个任务,并且图表加载正常,但它显示错误的日期例如2016年1月开发产品和发布部分。其实我没有在我的数据中使用这个日期。这里有什么问题?

可以你看看小提琴,让我知道这个问题。 HTML:

< script type =text / javascriptsrc =www.gstatic/charts/loader.js>< / script> < div id =chart_div>< / div>

Java script:

google.charts.load('current',{'packages':['gantt']}); google.charts.setOnLoadCallback(drawChart); 函数daysToMilliseconds(天){返回天数* 24 * 60 * 60 * 1000; function drawChart(){ var data = new google.visualization.DataTable(); data.addColumn('string','Task ID'); data.addColumn('string','任务名称'); data.addColumn('date','开始日期'); data.addColumn('date','结束日期')​​; data.addColumn('number','Duration'); data.addColumn('数字','完成百分比'); data.addColumn('string','Dependencies'); data.addRows([ ['Design','设计与分析',新日期(2015,8,1),新日期(2015,8,15 ),null,25,null], ['Development','开发产品', new新日期(2015,10,31) 20,null], ['Testing','产品测试',新日期(2015,11.01),新日期(2015,11,30),null,10,null], ['Release','Release the product', new Date(2015,12,01),new Date(2015,12,20),null,0,null], ]); var options = { height:275 }; var chart = new google.visualization.Gantt(document.getElementById('chart_div')); chart.draw(data,options); }

帮助并回复赞赏!

所以2015年12月1日将是 - > new Date(2015,11,01)

代替 12 将日期推到2016年1月1日

请参阅以下片段...

Date Test

console.log(new Date(2015,11,01 )); console.log(new Date(2015,12,01));

图表测试

如果范围应该是8 - 12月,那么每个月减1# b $ b

google.charts.load('current',{'packages':['gantt']}); google.charts.setOnLoadCallback(drawChart);函数daysToMilliseconds(days){return days * 24 * 60 * 60 * 1000; } function drawChart(){var data = new google.visualization.DataTable(); data.addColumn('string','Task ID'); data.addColumn('string','任务名称'); data.addColumn('date','开始日期'); data.addColumn('date','结束日期')​​; data.addColumn('number','Duration'); data.addColumn('数字','完成百分比'); data.addColumn('string','Dependencies'); data.addRows([['Design','Design and analysis',new Date(2015,7,1),new Date(2015,7,15),null,25,null],['Development','Develop产品',新日期(2015,7,16),新日期(2015,9,31),null,20,null],['测试','产品测试',新日期(2015,10,01) ,新日期(2015年11月20日),新日期(2015年11月20日),空日期(2015年10月30日),null,10,null],['Release','发布产品' ,0,null],]); var options = {height:275}; var chart = new google.visualization.Gantt(document.getElementById('chart_div')); chart.draw(数据,选项); }

< script type =text / javascriptsrc =www.gstatic/charts/loader.js>< / script>< div id =chart_div>< / div>

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 date for e.g. Jan 2016 in Develop the product and release section. Actually i haven't used this date in my data at all. What is the issue over here?

Can you take a look fiddle and let me know the issue please.

HTML:

<script type="text/javascript" src="www.gstatic/charts/loader.js"></script> <div id="chart_div"></div>

Java script:

google.charts.load('current', {'packages':['gantt']}); google.charts.setOnLoadCallback(drawChart); function daysToMilliseconds(days) { return days * 24 * 60 * 60 * 1000; } 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([ ['Design', 'Design and analysis', new Date(2015, 8, 1), new Date(2015, 8, 15), null, 25, null], ['Development', 'Develop the product', new Date(2015, 8, 16), new Date(2015, 10, 31), null, 20, null], ['Testing', 'Product testing', new Date(2015, 11, 01), new Date(2015, 11, 30), null, 10, null], ['Release', 'Release the product', new Date(2015, 12, 01), new Date(2015, 12, 20), null, 0, null], ]); var options = { height: 275 }; var chart = new google.visualization.Gantt(document.getElementById('chart_div')); chart.draw(data, options); }

Helps and reply appreciated!

解决方案

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(new Date(2015, 11, 01)); console.log(new Date(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); function daysToMilliseconds(days) { return days * 24 * 60 * 60 * 1000; } 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([ ['Design', 'Design and analysis', new Date(2015, 7, 1), new Date(2015, 7, 15), null, 25, null], ['Development', 'Develop the product', new Date(2015, 7, 16), new Date(2015, 9, 31), null, 20, null], ['Testing', 'Product testing', new Date(2015, 10, 01), new Date(2015, 10, 30), null, 10, null], ['Release', 'Release the product', new Date(2015, 11, 01), new Date(2015, 11, 20), null, 0, null], ]); var options = { height: 275 }; var chart = new google.visualization.Gantt(document.getElementById('chart_div')); chart.draw(data, options); }

<script type="text/javascript" src="www.gstatic/charts/loader.js"></script> <div id="chart_div"></div>

更多推荐

Google甘特图显示错误的一年

本文发布于:2023-10-28 23:30:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1538083.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   甘特图   Google

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!