首页 > 解决方案 > 当前版本的 Google Charts (v49) 打破了我的 google sheet table 可视化,而 v48 工作正常。为什么?

问题描述

我似乎对当前版本的谷歌图表(v49)有问题,它破坏了网站上谷歌表格表格的 HTML 可视化,而代码在 v48 上运行良好。

我怀疑这是由于根据 Google 发布说明进行了以下更改:“JSON 响应选项现在要求服务器返回严格的 JSON。”

但是,我不明白为什么我的样板(?) html 代码在 v49 下不起作用(或者为什么它没有返回符合 v49 的严格 JSON)。我还没有读到其他人有这个问题,我真的很想知道如何更新我的代码,以便它与最新(和未来)版本的谷歌图表一起运行。

在以下片段中,更改

google.charts.load('current', {packages: ['table']});
google.charts.load('48', {packages: ['table']});

使其运行没有任何问题。

我的问题:如何更改我的代码以使其适用于 v49。

<head>
<script src="https://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">

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

var visualization;

function drawVisualization() {
    var query = new google.visualization.Query('https://docs.google.com/spreadsheets/d/1p5feKZEBdCxoS3XDfxVjZu0zY4v3QpVYCgFbctwxlEA/edit?usp=sharing');
    query.setQuery('SELECT A, K, C');
    query.send(handleQueryResponse);
}

function handleQueryResponse(response) {
    if (response.isError()) {
        alert('There was a problem with your query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
        return;
    }
    var data = response.getDataTable();
    visualization = new google.visualization.Table(document.getElementById('table'));
    visualization.draw(data);
}

</script>

</head>
<body id="background">
  <div id="table"><h2>Please, wait. Google's visualization is obviously a bit slow at the moment...</h2>
  </div>
</body>

标签: javascripthtmlgoogle-sheetsgoogle-visualization

解决方案


推荐阅读