简体   繁体   English

Google互动图表

[英]Google Interactive Chart

HI All My requirement is To show a table( google interactive ) And download data of shown table in csv format. 大家好我的要求是显示一张表(Google交互式)并以csv格式下载显示的表数据。 I am using php. 我正在使用php。 My question is how will i create a datasource in mylocal syatem ? 我的问题是如何在mylocal syatem中创建数据源? What should be extension of datasource file ? 数据源文件的扩展名是什么? how will i write data in datasource? 我将如何在数据源中写入数据? How will i populate table wit this data ? 我将如何用这些数据填充表格? give a option to users to download it in csv format 给用户选择以csv格式下载的选项

To generate the table you'll want to check out the Google Charts Table documentation. 要生成表格,您需要查看Google Charts Table文档。 The code to generate a table will look something like: 生成表的代码如下所示:

   <head>
    <script type='text/javascript' src='https://www.google.com/jsapi'></script>
    <script type='text/javascript'>
      google.load('visualization', '1', {packages:['table']});
      google.setOnLoadCallback(drawTable);
      function drawTable() {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Name');
        data.addColumn('number', 'Salary');
        data.addColumn('boolean', 'Full Time Employee');
        data.addRows(2);
        data.setCell(0, 0, 'Mike');
        data.setCell(0, 1, 10000, '$10,000');
        data.setCell(0, 2, true);
        data.setCell(1, 0, 'Jim');
        data.setCell(1, 1, 8000, '$8,000');
        data.setCell(1, 2, false);    
        var table = new google.visualization.Table(document.getElementById('table_div'));
        table.draw(data, {showRowNumber: true});
      }
    </script>
  </head>

<div id='table_div'></div>

The data you're populating the table with will theoretically need to be stored server-side already. 从理论上讲,您用来填充表格的数据已经需要存储在服务器端。 You can store the data in a database such as a MySQL database, of which there are many tutorials online on how to set one up. 您可以将数据存储在MySQL数据库之类的数据库中,在线上有许多关于如何设置数据库的教程。

There are a number of ways to convert the data into a .csv file server-side. 有多种方法可以将数据转换为服务器端的.csv文件。 As an example, using PHP you could use fputcsv , by creating an arbitrary .csv file path on your server, then reading the data from your database to populate the .csv file. 例如,使用PHP可以使用fputcsv ,方法是在服务器上创建一个任意的.csv文件路径,然后从数据库中读取数据以填充.csv文件。 See the fputscsv documentation for examples on how to properly do this. 有关如何正确执行此操作的示例,请参见fputscsv文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM