如何正确使用谷歌可视化显示单元格'
How to correct cell's value displaying using Google visualization
我链接一个谷歌电子表格显示一些值在HTML中指向行索引和列索引的电子表格。括号内的值:
Abolenkin, Andrei (0,2)
它工作,但在编辑,排序,在相应的谷歌电子表格中添加新行后,单元格值与错误或空单元格交换:
Abolenkin, Andrei (0,0)
问题是如何正确地指向和修复链接单元格的值?
请查看电子表格和下面的代码
// https://google,developers.appspot.com/chart/interactive/docs/spreadsheets#gid
google.load('visualization', '1', {packages: ['corechart', 'line']});
google.setOnLoadCallback(drawChart);
function drawChart() {
var spreadsheetUrl = "https://docs.google.com/spreadsheets/d/1tTfV1DwfbipOvCMGMhekNIDRVDROwhrvofjA5YE2JHY/edit#gid=0range=A";
var query = new google.visualization.Query(spreadsheetUrl);
query.send(handleQueryResponse);
}
function handleQueryResponse(response) {
var dataTable = response.getDataTable();
// https://developers.google.com/chart/interactive/docs/reference?hl=en#methods
// getValue(rowIndex, columnIndex)
document.getElementById("Abolenkin").innerHTML = dataTable.getFormattedValue(0, 0);
document.getElementById("Akhmadullina").innerHTML = dataTable.getFormattedValue(1, 0);
var date = (new Date().getFullYear()).toString();
document.getElementById("year").innerHTML = date;
}
/* Indexmod CSS */
/* Лого */
.header {
padding:0px;
margin:30;
}
/* Страница */
.content {
padding: 20px;
margin: auto;
font: 20px Georgia, serif;
line-height: 27px;
}
h1 {
font-size:70px;
font-family: "Helvetica Neue", Arial, sans-serif;
font-weight:100;
-webkit-font-smoothing:antialiased;
}
li {
list-style: none;
list-style-type:none
}
a:link {color:black; text-decoration:none}
a:visited {color:black; text-decoration:none}
a:hover {color:black; text-decoration:underline}
a:active {color:black; text-decoration:none}
/* Подвал */
.footer {
margin: auto;
}
#year {
vertical-align: super;
font-family: Georgia;
font-size: 12px;
color: black;
}
.what {
vertical-align: super;
font-family: Georgia;
font-size: 12px;
color: black;
}
.name {
font-weight: bold;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<!--[if lt IE 9]><script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"></script><![endif]-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script src="code.js"></script>
</head>
<body>
<link href="style.css" rel="stylesheet">
<main class="content">
<p id="Abolenkin-Andrei"> <span class=name>Abolenkin, Andrei</span> (<span id="Abolenkin"></span><a class=what href="http://www.indexmod.info/indexmod" title="Based on the Indexmod algorithm. Click for more info.">?</a>), Andrei Abolenkin; A.K.A Nekto Abolenkin; Rus. Андрей Аболенкин; Некто Аболенкин; born 1972, Moscow, is a Russian style and fashion expert, consultant and promoter. <a href="http://sites.google.com/site/indexmodencyclopedia/abolenkin-andrei"> Login to edit entire article indexmod.info/abolenkin-andrei</a></p>
<p id="Akhmadullina-Alena"> <span class=name>Akhmadullina, Alena</span> (<span id="Akhmadullina"></span><a class=what href="http://www.indexmod.info/indexmod" title="Based on the Indexmod algorithm. Click for more info.">?</a>), Rus. Алёна Ахмадуллина, born 1978, Sosnovy Bor, Leningrad Oblast, is a Russian fashion designer, founder of the brand Alena Akhmadullina, participant of various Russian and international competitions in the field of fashion, мember of “Snob” from April 2009.</p>
</main>
</body>
</html>
如果电子表格已排序,则不能保证所需的值分别位于第0行和第1行
dataTable.getFormattedValue(0, 0) //<-- (row, column)
getFilteredRows
方法。参见以下工作代码片段中的findValue
函数,
使用表格图表来帮助可视化问题
google.load('visualization', '1', {packages: ['corechart', 'table']});
google.setOnLoadCallback(drawChart);
function drawChart() {
var spreadsheetUrl = "https://docs.google.com/spreadsheets/d/1tTfV1DwfbipOvCMGMhekNIDRVDROwhrvofjA5YE2JHY/edit#gid=0range=A";
var query = new google.visualization.Query(spreadsheetUrl);
query.send(handleQueryResponse);
}
function handleQueryResponse(response) {
var dataTable = response.getDataTable();
//var container = document.getElementById("chart_div");
//var chart = new google.visualization.Table(container);
//chart.draw(dataTable);
document.getElementById("Abolenkin").innerHTML = findValue("Abolenkin");
document.getElementById("Akhmadullina").innerHTML = findValue("Akhmadullina");
function findValue(surname) {
var value = '';
var rowsFound = dataTable.getFilteredRows([{
column: 7,
value: surname
}]);
if (rowsFound.length > 0) {
value = dataTable.getFormattedValue(rowsFound[0], 0);
}
return value;
}
}
div {
padding: 8px;
}
<script src="https://www.google.com/jsapi"></script>
<div>
Abolenkin: <span id="Abolenkin"></span>
</div>
<div>
Akhmadullina: <span id="Akhmadullina"></span>
</div>
<div id="chart_div"></div>
相关文章:
- ui网格将单元格显示为选择标记
- 单元格的工具提示或标题不显示超过2000个字符
- ui网格日期单元格过滤器,过滤日期格式导致显示错误的日期
- 使用下拉选择菜单高亮显示一行表格单元格
- 正在擦除要重新显示的单元格
- 每行仅突出显示一个单元格
- 将突出显示的单元格返回到php
- 只在表中突出显示一个单元格值
- 单击并用CTRL+C复制值时高亮显示html表格单元格
- 选择并高亮显示一行中的单元格
- 我希望joint.js库读取我的JSON并将其显示为一个单元格:rect和circle
- 谷歌电子表格在多个单元格中显示脚本中的值
- 从所选内容中选择选项,并在表格单元格中显示所选内容的信息
- 带有大型JSON的简单ngTable在单元格中不显示任何数据
- JQuery 显示来自可见 HTML 表格单元格的文本的串联列表
- Asp.net 客户端单击显示表中其他单元格的值
- 将显示:无设置为第一行的单元格会弄乱表格布局
- 如何使用 CSS 和 jQuery 根据表单元格值有条件地在悬停时突出显示表行
- 如何在角度UI网格中突出显示具有最大单元格值的行
- 单元格值未在使用自定义下拉列表编辑器的剑道 UI 网格中正确显示