我在Google图表中的信息中心存在问题。当前,除了柱形图在Y轴上显示字符串而不是整数之外,其他所有东西都起作用。
我发现Google图表页面上的文档非常难以理解,因此,如果我的代码中有错误,或者有一种简单的方法可以完成工作,我深表歉意。
我的JS小提琴如下所示: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);
}
最佳答案
如果您还没有这样做,请查看ColumnChart Configuration Options以查看您必须玩什么。通过为垂直轴指定数字格式,您将获得数字。不幸的是,如果没有bunch of additional code,即使数据全是整数,gViz仍将决定您必须要看到分数。
Updated jsFiddle。
//define the column chart
var columnChart = new google.visualization.ChartWrapper({
'chartType': 'ColumnChart',
'options' : {
'hAxis' : { 'title' : 'Student Name' },
'legend' : {position: 'none' },
'vAxis' : {format: 'short',
title: 'Number Attended'}
},
'containerId' : 'column_div',
});