谷歌时间表图表从错误的日期开始

时间:2015-12-14 08:40:13

标签: javascript jquery charts

  google.load("visualization", "1", {packages:["timeline"]});
  google.setOnLoadCallback(drawChart);

  function drawChart() 
  {
    var container = document.getElementById('chart_div');
    var chart = new google.visualization.Timeline(container);
    var dataTable = new google.visualization.DataTable();

    dataTable.addColumn({ type: 'string', id: 'DMAIC' });
    dataTable.addColumn({ type: 'string', id: 'Pozicija' });
    dataTable.addColumn({ type: 'string', 'role': 'tooltip', 'p': {'html': true}})
    dataTable.addColumn({ type: 'date', id: 'Start' });
    dataTable.addColumn({ type: 'date', id: 'End' });
    dataTable.addRows([['Opredelitev', 'Plan' , '<div class="timelineHover"><p style="padding:2px;font-weight:bold;">10.12.2015 - 19.12.2015</p></div>', new Date(2015, 12, 10), new Date(2015, 12, 19)],['Meritev', 'Plan' , '<div class="timelineHover"><p style="padding:2px;font-weight:bold;">09.12.2015 - 16.01.2016</p></div>', new Date(2015, 12, 09), new Date(2016, 01, 16)],['Analiza', 'Plan' , '<div class="timelineHover"><p style="padding:2px;font-weight:bold;">18.12.2015 - 24.12.2015</p></div>', new Date(2015, 12, 18), new Date(2015, 12, 24)],['Izboljšava', 'Plan' , '<div class="timelineHover"><p style="padding:2px;font-weight:bold;">12.01.2016 - 23.01.2016</p></div>', new Date(2016, 01, 12), new Date(2016, 01, 23)],['Kontrola', 'Plan' , '<div class="timelineHover"><p style="padding:2px;font-weight:bold;">07.01.2016 - 23.01.2016</p></div>', new Date(2016, 01, 07), new Date(2016, 01, 23)],['Replikacija', 'Plan' , '<div class="timelineHover"><p style="padding:2px;font-weight:bold;">08.02.2016 - 26.02.2016</p></div>', new Date(2016, 02, 08), new Date(2016, 02, 26)],['Opredelitev', 'Realizacija', '<div class="timelineHover"><p style="padding:2px;font-weight:bold;">17.12.2015 - 25.12.2015</p></div>', new Date(2015, 12, 17), new Date(2015, 12, 25)]]);

    var options = {
        width:950,
        height:430,
        backgroundColor: '#ffd',
        timeline: { colorByRowLabel: true },
        tooltip: {isHtml: true}
    };
    chart.draw(dataTable, options);
  }

http://jsfiddle.net/r37uf/50/

在这个例子中,我最早的值以

开头
new Date(2015, 12, 9)

应该是12月9日,但我的图表从1月9日开始。

1 个答案:

答案 0 :(得分:1)

月份,日期格式为月号​​ - 1,因此您应该使用 12月new Date(2015, 11, 9)

1月是0月,如果提供不正确,则为默认月份(12不正确)