2013-01-23 31 views
0

在谷歌游乐场一直搞乱这个,它似乎工作没有任何错误。但是,当我去做出口选项时,它不会给我任何东西。任何想法?谷歌可视化数据表不会去csv

<!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> 

回答

1

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

使用 使用工具栏,可视化必须从一个URL的数据;您无法传递手动填充的DataTable或DataView对象。您将传递用于填充可视化对象的数据的URL到drawToolbar()方法中。

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'; 
}); 

说明:

Check my answer posted here for an explanation of the code.Export与下载选项页面上的锚元素的ID。