【发布时间】:2015-04-09 15:59:27
【问题描述】:
我在 Google 图表中的信息中心有问题。目前一切正常,除了柱形图在 Y 轴上显示一个字符串而不是一个整数。
我发现 Google 图表页面上的文档很难理解,因此如果我的代码中有错误,或者如果有更简单的方法我可以完成,我深表歉意。
我的 JS Fiddle 如下图所示:https://jsfiddle.net/hm7q5peg/6/
google.load('visualization', '1.0', {
'packages': ['corechart','table', 'controls']
});
google.setOnLoadCallback(drawDashboard);
function drawDashboard() {
// Using the jsapi, it's better to set the url
// for the spreadsheet, then use setQuery() to
// define the query that will provide your data.
var url = '//docs.google.com/spreadsheet/ccc?key=1FOVmfesx7ATNe8qjWjkU2GbjBCBZxL0BRswJv6rcGPs&usp=drive_web&gid=1324373577';
var query = new google.visualization.Query(url);
query.setQuery('select B,C where B <> ""');
// Send the query with a callback function
query.send(handleQueryResponse);
}
function handleQueryResponse(response) {
// Called when the query response is returned.
if (response.isError()) {
alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
return;
}
var data = response.getDataTable();
var dashboard = new google.visualization.Dashboard(
document.getElementById('dashboard_div'));
// Create a range slider, passing some options
var donutRangeSlider = new google.visualization.ControlWrapper({
'controlType': 'NumberRangeFilter',
'containerId': 'filter_div',
'options': {
'filterColumnLabel': 'Number Attended'
}
});
// Create a pie chart, passing some options
var pieChart = new google.visualization.ChartWrapper({
'chartType': 'PieChart',
'containerId': 'chart_div',
'options': {
'width': 300,
'height': 300,
'pieSliceText': 'value',
'legend': 'right'
}
});
//define a table
var table = new google.visualization.ChartWrapper({
'chartType': 'Table',
'containerId': 'table_div',
'options': {
'width':'300px'
}
});
//define the column chart
var columnChart = new google.visualization.ChartWrapper({
'chartType': 'ColumnChart',
'containerId' : 'column_div',
});
// Establish dependencies, declaring that 'filter' drives 'pieChart',
// so that the pie chart will only display entries that are let through
// given the chosen slider range.
dashboard.bind(donutRangeSlider, [pieChart, table, columnChart]);
// Draw the dashboard.
dashboard.draw(data);
}
【问题讨论】:
标签: javascript google-apps-script google-visualization google-docs google-spreadsheet-api