我正在使用谷歌注释图表遇到一些问题。我从Google提供的示例开始,然后尝试通过Fiddle调整它以使用来自google sheets document的查询中的数据。
我觉得我已经搞乱了查询本身,或者将查询结果放入图表并绘制它。
非常感谢任何帮助。我的Javscript包含在下面。
google.charts.load('current', {'packages':['annotationchart']});
google.charts.setOnLoadCallback(drawChart);
function initialize() {
var opts = {sendMethod: 'auto'};
// Replace the data source URL on next line with your data source URL.
var query = new google.visualization.Query('https://docs.google.com/spreadsheets/d/1KVOMq2usUg-FRmfx9cnGgJVR-wQZ2oJcyufaIgcxzFw', opts);
// Optional request to return only column C and the sum of column B, grouped by C members.
query.setQuery('select B, select G');
// Send the query with a callback function.
query.send(handleQueryResponse);
}
function handleQueryResponse(response) {
if (response.isError()) {
alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
return;
}
var data = response.getDataTable();
var chart = new google.visualization.AnnotationChart(document.getElementById('chart_div'));
var options = {
displayAnnotations: false
};
chart.draw(data, options);
}
答案 0 :(得分:0)
drawChart
至 - initialize
load
声明中,而不是使用 - setOnLoadCallback
)select B, select G
至 - select B, G
query.setQuery
)请参阅以下工作代码段...
google.charts.load('current', {
callback: initialize,
packages: ['annotationchart']
});
function initialize() {
var opts = {sendMethod: 'auto'};
// Replace the data source URL on next line with your data source URL.
var query = new google.visualization.Query('https://docs.google.com/spreadsheets/d/1KVOMq2usUg-FRmfx9cnGgJVR-wQZ2oJcyufaIgcxzFw/gviz/tq?tq=select B,G', opts);
// Send the query with a callback function.
query.send(handleQueryResponse);
}
function handleQueryResponse(response) {
if (response.isError()) {
alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
return;
}
var data = response.getDataTable();
var chart = new google.visualization.AnnotationChart(document.getElementById('chart_div'));
var options = {
displayAnnotations: false
};
chart.draw(data, options);
}

<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
&#13;