javascript - 当前版本的 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>
解决方案
推荐阅读
- camera - 如何在 p5.js 中创建 3d 游戏。相机位置?
- ruby-on-rails - Config Field::Select.with_options 集合作为 adminitrate 中的模型方法
- swift - 第一次未设置 Swift UI 属性
- java - 未添加到类路径的测试资源
- python - 平面 json 到嵌套 json python
- c# - C# 获取目录名称
- r - base::cut() 在计算值上产生错误的结果。这是一个已知的错误?
- javascript - 从 Buffer.from() 解码结果
- r - 使用观察事件时如何在传单中的标记和簇之间切换?
- excel - Python xlsxwriter 图表:如果系列在主轴或次轴上,有什么方法可以在图例中显示?