Javascript 将Google工作表作为Google甘特图的数据源

Javascript 将Google工作表作为Google甘特图的数据源,javascript,charts,google-sheets,google-visualization,Javascript,Charts,Google Sheets,Google Visualization,我正试图从谷歌工作表中提取数据,并将其用作我工作的来源。我在GoogleCharts文档中遵循了这个例子,但不确定是否需要更多的定制 我对Javascript不太熟悉,所以不确定是什么触发了错误。下面是中的代码 首先,回调应该是-->drawGID 而不是-->drawChart 接下来,请注意甘特图的 'Start'和'End'日期都是必需的,不能为空, 如电子表格所示 请参阅以下工作片段 使用电子表格中的数据(otherData)构建新的数据表, 使用“持续时间”列填写日期 googl

我正试图从谷歌工作表中提取数据,并将其用作我工作的来源。我在GoogleCharts文档中遵循了这个例子,但不确定是否需要更多的定制

我对Javascript不太熟悉,所以不确定是什么触发了错误。下面是中的代码


首先,
回调
应该是-->
drawGID

而不是-->
drawChart


接下来,请注意甘特图的

'Start'
'End'
日期都是必需的,不能为空,
如电子表格所示


请参阅以下工作片段

使用电子表格中的数据(
otherData
)构建新的数据表,
使用
“持续时间”
列填写日期

google.charts.load('current'{
回调:drawGID,
软件包:[“甘特”]
});
函数drawGID(){
var queryString=encodeURIComponent('选择A、B、C、D、E、F、G、H');
var query=new google.visualization.query(
'https://docs.google.com/spreadsheets/d/1f0wxDrEfptRKCRY5pQPu6Dc_ue_tIX_ja5pQO3vXjOY/edit#gid=0&headers=1&tq=“+查询字符串);
发送(handleSampleDataQueryResponse);
}
函数handleSampleDataQueryResponse(响应){
if(response.isError()){
警报('查询中的错误:'+response.getMessage()+'+response.getDetailedMessage());
回来
}
var otherData=response.getDataTable();
var ganttData=new google.visualization.DataTable({cols:[
{类型:'string',标签:'Task Id'},
{类型:'string',标签:'Task Name'},
{类型:'string',标签:'Resource'},
{类型:'date',标签:'Start'},
{类型:'date',标签:'End'},
{类型:'number',标签:'Duration'},
{类型:'number',标签:'%Complete'},
{类型:'string',标签:'Dependencies'}
]});
var持续时间=0;
var startDate=新日期(2016年0月1日);
var结束日期;
对于(var i=0;i

以下Google项目允许您以甘特图的形式查看Google电子表格:

google.charts.load('current', {'packages':['gantt']});
google.charts.setOnLoadCallback(drawChart);

function daystoMilliseconds(days) {
  return days * 24 * 60 * 60 * 1000;
}

function drawGID() {
  var queryString = encodeURIComponent('SELECT A, B, C, D, E, F, G, H');

  var query = new google.visualization.Query(
      'https://docs.google.com/spreadsheets/d/1f0wxDrEfptRKCRY5pQPu6Dc_ue_tIX_ja5pQO3vXjOY/edit#gid=0&headers=1&tq=' + queryString);
  query.send(handleSampleDataQueryResponse);
}

function handleSampleDataQueryResponse(response) {
  if (response.isError()) {
    alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
    return;
  }}

function drawChart() {

  var otherData = response.getDataTable();

  var options = {
    height: 275,
    gantt: {
      defaultStartDateMillis: new Date(2015, 3, 28)
    }
  };

  var chart = new google.visualization.Gantt(document.getElementById('chart_div'));

  chart.draw(otherData, options);
}