0

在谷歌操场上搞砸了这个,它似乎没有任何错误。但是,当我去做导出选项时,它什么也没给我。任何想法?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>
  Google Visualization API Sample
</title>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
  google.load('visualization', '1', {packages: ['table']});
</script>
<script type="text/javascript">
function drawVisualization() {
  // Create and populate the data table.
  var data = google.visualization.arrayToDataTable([
    ['Name', 'Height', 'Smokes'],
    ['Tong Ning mu', 174, true],
    ['Huang Ang fa', 523, false],
    ['Teng nu', 86, true]
  ]);
  var options = { 'showRowNumber': true };
  options['page'] = 'enable';
  options['pageSize'] = 3;
  options['pagingSymbols'] = { prev: 'prev', next: 'next' };
  options['pagingButtonsConfiguration'] = 'auto';

  var components = [
    { type: 'html', datasource: data },
    { type: 'csv', datasource: data }
  ];

  var container = document.getElementById('toolbar_div');
  google.visualization.drawToolbar(container, components);

  // Create and draw the visualization.
  visualization = new google.visualization.Table(document.getElementById('table'));
  visualization.draw(data, options);
}


google.setOnLoadCallback(drawVisualization);
</script>
</head>
<body style="font-family: Arial;border: 0 none;">
<div id="table"></div>
<dov id="toolbar_div"></div>
</body>
</html>

​</p>

4

2 回答 2

1

根据文档,您必须通过 URL 而不是任何手动填充的数据对象传递数据。请参阅: https ://developers.google.com/chart/interactive/docs/gallery/toolbar

用法 要使用工具栏,您的可视化必须从 URL 获取其数据;您不能传入手动填充的 DataTable 或 DataView 对象。您将用于填充可视化的数据的 URL 传递到 drawToolbar() 方法中。

于 2013-05-17T09:12:07.950 回答
0

代码:

$('#Export').click(function () {
    var csvFormattedDataTable = google.visualization.dataTableToCsv(data);
    var encodedUri = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csvFormattedDataTable);
    this.href = encodedUri;
    this.download = 'table-data.csv';
    this.target = '_blank';
});

解释:

查看我在此处发布的答案以获取代码说明。 Export是带有下载选项的页面上锚元素的 ID。

于 2016-07-15T02:56:30.697 回答