Javascript //画一张图表#1 //------------------------------------------------------------------ //创建图表#1。 //请注意,DOM元素ID必须与 符合的 //HTML正文部分中的ID。 //
//画一张图表#1 //------------------------------------------------------------------ //创建图表#1。 //请注意,DOM元素ID必须与 符合的 //HTML正文部分中的ID。 //我们将展示主场出勤率、得分、允许得分、胜利、, 输了,没有比赛落后。 var chartView=newgoogle.visualization.DataView(数据); 设置列([4,5]); var chart2=新的google.visualization.ChartWrapper(); chart2.setChartType(“柱形图”); 图2.setContainerId('chart1_div'); chart2.setView(chartView.toJSON()); //创建图表。 //请注意,DOM元素ID必须与 符合的 //HTML正文部分中的ID。 //var myChart=new ColumnChart(document.getElementById('chart1_div'); //myChart.draw(图表视图); //------------------------------------------------------------------ //画一张图表#2 //------------------------------------------------------------------ //创建图表#2。 //请注意,DOM元素ID必须与 符合的 //HTML正文部分中的ID。 //我们将展示主场出勤率、得分、允许得分、胜利、, 输了,没有比赛落后。 var chartView2=新的google.visualization.DataView(数据); chartView2.setColumns([0,7,8,9]); var chart3=新的google.visualization.ChartWrapper(); 图表3.setChartType(“柱形图”); 图3.setContainerId('chart2_div'); chart3.setView(chartView2.toJSON()); //创建图表#2。 //请注意,DOM元素ID必须与 符合的 //HTML正文部分中的ID。 //var myChart2=新 ColumnChart(document.getElementById('chart2_div'); //myChart2.绘图(chartView2); //创建并绘制仪表板 var仪表板=新 Dashboard(document.getElementById('Dashboard_div'); //将过滤器绑定到图表。这些过滤器和图表现在成为 此仪表板的一部分。 dashboard.bind([chart1,chart2,chart3]); //在此仪表板中绘制所有图表和过滤器。 仪表盘.绘图(数据); } 项目1:电子表格显示工作Javascript //画一张图表#1 //------------------------------------------------------------------ //创建图表#1。 //请注意,DOM元素ID必须与 符合的 //HTML正文部分中的ID。 //,javascript,google-visualization,Javascript,Google Visualization,//画一张图表#1 //------------------------------------------------------------------ //创建图表#1。 //请注意,DOM元素ID必须与 符合的 //HTML正文部分中的ID。 //我们将展示主场出勤率、得分、允许得分、胜利、, 输了,没有比赛落后。 var chartView=newgoogle.visualization.DataView(数据); 设置列([4,5]); var chart2=新的google.vis
代码中的问题在哪里?很抱歉,我忘了将问题代码放在工作代码中。请您清理一下,如果代码与您发布的代码完全一致,您会收到很多注释,因为代码已经解决了问题。谢谢
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', { 'packages': ['corechart', 'table']
});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(sendQuery);
// Construct and send a query to Google Spreadsheet
function sendQuery() {
var query = new google.visualization.Query(
'https://docs.google.com/spreadsheets/d/1Ixlanep_0VfZtnk4rzS0jb1owTIbIRWAdGr9mp7OMIc/gviz/tq?tq=');
//query.setQuery('SELECT E, F, H, I');
query.send(drawChart);
}
// The query callback function
function drawChart(response) {
// Always check for error.
if (response.isError()) {
alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
return;
}
// Get DataTable from the "response" object. This is the result from your query.
// This DataTable must conform to the data format required by the chart you will draw next.
// To find out, read the Google Chart document at
// https://developers.google.com/chart/interactive/docs/
var data = response.getDataTable();
// Sort by the first column.
data.sort([{column: 0 }]);
//--------------------------------------------------------------------------
// Draw a table
//--------------------------------------------------------------------------
// We'll show the whole table. So there is no need to set call setColumns().
var tableView = new google.visualization.DataView(data);
// Create the table.
// Note that DOM element ID must be consistent with the corresponding
// ID in the HTML body section.
var myTable = new google.visualization.Table(document.getElementById('table_div'));
myTable.draw(tableView);
//--------------------------------------------------------------------------
// Draw a chart #1
//--------------------------------------------------------------------------
// Create the chart #1.
// Note that DOM element ID must be consistent with the
corresponding
// ID in the HTML body section.
// We'll show home game attendance, runs scored, runs allowed, wins, loses, and NO# games behind .
var chartView = new google.visualization.DataView(data);
chartView.setColumns([4, 5]);
// Create the chart.
// Note that DOM element ID must be consistent with the corresponding
// ID in the HTML body section.
var myChart = new google.visualization.ColumnChart(document.getElementById('chart1_div'));
myChart.draw(chartView);
//--------------------------------------------------------------------------
// Draw a chart #2
//--------------------------------------------------------------------------
// Create the chart #2.
// Note that DOM element ID must be consistent with the corresponding
// ID in the HTML body section.
// We'll show home game attendance, runs scored, runs allowed, wins, loses, and NO# games behind .
var chartView2 = new google.visualization.DataView(data);
chartView2.setColumns([0, 7, 8, 9]);
// Create the chart #2.
// Note that DOM element ID must be consistent with the
corresponding
// ID in the HTML body section.
var myChart2 = new google.visualization.
ColumnChart(document.getElementById('chart2_div'));
myChart2.draw(chartView2);
}
</script>
</head>
<body>
<h2>Project 1: Spreadsheet display working</h2>
<!--Div that will hold the pie chart-->
<div id="table_div"></div>
<div id="chart1_div"></div>
<div id="chart2_div"></div>
</body>
</html>
PROBLEM CODE
<html>
<head>
<title>Project 1: Spreadsheet display working</title>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', { 'packages': ['controls', 'map',
'table', 'corechart'] });
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(sendQuery);
// Construct and send a query to Google Spreadsheet
function sendQuery() {
var query = new google.visualization.Query(
'https://docs.google.com/spreadsheets/d/1Ixlanep_0VfZtnk4rzS0jb1owTIbIRWAdGr9mp7
OMIc/gviz/tq?tq=');
//query.setQuery('SELECT E, F, H, I');
query.send(drawChart);
}
// The query callback function
function drawChart(response) {
// Always check for error.
if (response.isError()) {
alert('Error in query: ' + response.getMessage() + ' ' +
response.getDetailedMessage());
return;
}
var data = response.getDataTable();
// Sort by the first column.
data.sort([{column: 0 }]);
//------------------------------------------------------------------
// Draw a table
//------------------------------------------------------------------
// We'll show the whole table. So there is no need to set call
setColumns().
var tableView = new google.visualization.DataView(data);
// Create an empty ChartWrapper and set its properties
var chart1 = new google.visualization.ChartWrapper();
chart1.setChartType('Table');
chart1.setContainerId('table_div');
// To set a DataView for the ChartWrapper, use
DataView.toJSON()function.
// There is a no need to set DataTable for the ChartWrapper.
chart1.setView(tableView.toJSON());
//------------------------------------------------------------------
// Draw a chart #1
//------------------------------------------------------------------
// Create the chart #1.
// Note that DOM element ID must be consistent with the
corresponding
// ID in the HTML body section.
// We'll show home game attendance, runs scored, runs allowed, wins,
loses, and NO# games behind .
var chartView = new google.visualization.DataView(data);
chartView.setColumns([4, 5]);
var chart2 = new google.visualization.ChartWrapper();
chart2.setChartType('ColumnChart');
chart2.setContainerId('chart1_div');
chart2.setView(chartView.toJSON());
// Create the chart.
// Note that DOM element ID must be consistent with the
corresponding
// ID in the HTML body section.
//var myChart = new
google.visualization.ColumnChart(document.getElementById('chart1_div'));
//myChart.draw(chartView);
//------------------------------------------------------------------
// Draw a chart #2
//------------------------------------------------------------------
// Create the chart #2.
// Note that DOM element ID must be consistent with the
corresponding
// ID in the HTML body section.
// We'll show home game attendance, runs scored, runs allowed, wins,
loses, and NO# games behind .
var chartView2 = new google.visualization.DataView(data);
chartView2.setColumns([0, 7, 8, 9]);
var chart3 = new google.visualization.ChartWrapper();
chart3.setChartType('ColumnChart');
chart3.setContainerId('chart2_div');
chart3.setView(chartView2.toJSON());
// Create the chart #2.
// Note that DOM element ID must be consistent with the
corresponding
// ID in the HTML body section.
//var myChart2 = new
google.visualization.ColumnChart(document.getElementById('chart2_div'));
//myChart2.draw(chartView2);
// Create and draw the dashboard
var dashboard = new
google.visualization.Dashboard(document.getElementById('dashboard_div'));
// Bind the filters to charts. These filters and charts now become
part of this dashboard.
dashboard.bind([chart1, chart2, chart3]);
// Draw all the charts and filters in this dashboard.
dashboard.draw(data);
}
</script>
</head>
<body>
<h2>Project 1: Spreadsheet display working</h2>
<div id="dashboard_div">
<table>
<tr>
<td>
<!--Div that will hold the pie chart-->
<div id="table_div" style="height: 200px; width: 1000px;
border-style: groove;">
</div>
<br />
<div id="chart1_div" style="height: 200px; width: 1000px;
border-style: groove;">
</div>
<br />
<div id="chart2_div" style="height: 200px; width: 1000px;
border-style: groove;">
</div>
</td>
</tr>
</table>
</div>
</body>
</html>