<script type="text/javascript">
// google.load('visualization', '1.1', { packages: ['controls'] });
google.load('visualization', '1', { packages: ['table'] });
</script>
<script type="text/javascript">
function drawVisualization(dataValues, chartTitle, columnNames, categoryCaption) {
if (dataValues.length < 1)
return;
var data = new google.visualization.DataTable();
data.addColumn('string', columnNames.split(',')[0]);
data.addColumn('string', columnNames.split(',')[1]);
data.addColumn('string', columnNames.split(',')[2]);
data.addColumn('string', columnNames.split(',')[3]);
data.addColumn('string', columnNames.split(',')[4]);
data.addColumn('string', columnNames.split(',')[5]);
data.addColumn('number', columnNames.split(',')[6]);
data.addColumn('number', columnNames.split(',')[7]);
data.addColumn('string', 'Email');
for (var i = 0; i < dataValues.length; i++) {
data.addRow([dataValues[i].Value1, dataValues[i].Value2, dataValues[i].Value3, dataValues[i].Value4, dataValues[i].Value5, dataValues[i].Value6, dataValues[i].Value7, dataValues[i].Value8, 'contactus.aspx']);
}
var table = new google.visualization.Table(document.getElementById('TableContainer'));
var formatter = new google.visualization.PatternFormat('<a href="{8}">{7}</a>');
formatter.format(data, [7, 8]); // Apply formatter and set the formatted value of the first column.
var view = new google.visualization.DataView(data);
view.setColumns([0,1,2,3,4,5,6,7]); // Create a view with the first column only.
table.draw(view, { allowHtml: true, showRowNumber: true });
}
</script>
简短的谷歌表格图表代码;提到https://developers.google.com/chart/interactive/docs/reference?hl=de-DE#patternformatter 我试图添加链接按钮;我无法告诉我哪里出错了;请将一些链接告诉我......谢谢。
答案 0 :(得分:3)
问题在于以下几点:
var formatter = new google.visualization.PatternFormat('<a href="{8}">{7}</a>');
formatter.format(data, [7, 8]);
模式中的数字是指传递给格式化程序的数组的标记,而不是列索引。您的案例中的模式应如下所示:
var formatter = new google.visualization.PatternFormat('<a href="{1}">{0}</a>');
因为您希望将格式化程序中的第一列用作链接的文本,将格式化程序中的第二列用作href属性。