• <i id='3anGF'><tr id='3anGF'><dt id='3anGF'><q id='3anGF'><span id='3anGF'><b id='3anGF'><form id='3anGF'><ins id='3anGF'></ins><ul id='3anGF'></ul><sub id='3anGF'></sub></form><legend id='3anGF'></legend><bdo id='3anGF'><pre id='3anGF'><center id='3anGF'></center></pre></bdo></b><th id='3anGF'></th></span></q></dt></tr></i><div id='3anGF'><tfoot id='3anGF'></tfoot><dl id='3anGF'><fieldset id='3anGF'></fieldset></dl></div>

      <legend id='3anGF'><style id='3anGF'><dir id='3anGF'><q id='3anGF'></q></dir></style></legend>

      1. <small id='3anGF'></small><noframes id='3anGF'>

        <tfoot id='3anGF'></tfoot>

          <bdo id='3anGF'></bdo><ul id='3anGF'></ul>
      2. 从多个 csv 文件中绘制网站中的数据

        时间:2023-10-02
        <i id='tqJJM'><tr id='tqJJM'><dt id='tqJJM'><q id='tqJJM'><span id='tqJJM'><b id='tqJJM'><form id='tqJJM'><ins id='tqJJM'></ins><ul id='tqJJM'></ul><sub id='tqJJM'></sub></form><legend id='tqJJM'></legend><bdo id='tqJJM'><pre id='tqJJM'><center id='tqJJM'></center></pre></bdo></b><th id='tqJJM'></th></span></q></dt></tr></i><div id='tqJJM'><tfoot id='tqJJM'></tfoot><dl id='tqJJM'><fieldset id='tqJJM'></fieldset></dl></div>

        1. <legend id='tqJJM'><style id='tqJJM'><dir id='tqJJM'><q id='tqJJM'></q></dir></style></legend>
          <tfoot id='tqJJM'></tfoot>

            • <small id='tqJJM'></small><noframes id='tqJJM'>

                  <tbody id='tqJJM'></tbody>
                • <bdo id='tqJJM'></bdo><ul id='tqJJM'></ul>
                  本文介绍了从多个 csv 文件中绘制网站中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我创建了一个 静态网站 托管在 AWS s3 存储桶上.

                  I made a static website hosted on an AWS s3 bucket.

                  我不了解有关 Web 开发的工具和技术,但我举了一个 index.html 代码示例,该代码允许我从名为my_data_file1.csv"的单个文件中绘制数据.

                  I do not know the tools and technology around web development, but I took an example of index.html code allowing me to plot data from a single file named "my_data_file1.csv".

                  <!DOCTYPE html>
                  <html lang="en">
                    <head>
                      <meta charset="UTF-8" />
                      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
                      <meta http-equiv="X-UA-Compatible" content="ie=edge" />
                      <title>Coding Train: Data and APIs Project 1</title>
                      <script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0"></script>
                    </head>
                    <body>
                      <h1>Global Temperatures</h1>
                      <canvas id="myChart" width="400" height="200"></canvas>
                  
                      <script>
                  
                        window.addEventListener('load', setup);
                  
                        async function setup() {
                          const ctx = document.getElementById('myChart').getContext('2d');
                          const globalTemps = await getData();
                          const myChart = new Chart(ctx, {
                            type: 'line',
                            data: {
                              labels: globalTemps.years,
                              datasets: [
                                {
                                  label: 'Temperature in °C',
                                  data: globalTemps.temps,
                                  fill: false,
                                  borderColor: 'rgba(255, 99, 132, 1)',
                                  backgroundColor: 'rgba(255, 99, 132, 0.5)',
                                  borderWidth: 1
                                }
                              ]
                            },
                            options: {}
                          });
                        }
                  
                        async function getData() {
                          const response = await fetch('my_data_file1.csv');
                          const data = await response.text();
                          const years = [];
                          const temps = [];
                          const rows = data.split('
                  ').slice(1);
                          rows.forEach(row => {
                            const cols = row.split(',');
                            years.push(cols[0]);
                            temps.push(parseFloat(cols[2]));
                          });
                          return { years, temps };
                        }
                      </script>
                    </body>
                  </html>
                  

                  我的所有数据都拆分为多个文件,因此我希望能够说明一个目录中的所有 CSV 文件,而不仅仅是一个.我的文件名是可变的,所以我不能一一列出.是否可以将过滤器或正则表达式用作*.csv"?提前致谢,

                  All of my data is split into multiple files, so I would like to be able to account for all the CSV files in a directory, rather than just one. The name of my files is variable, so I cannot list them one by one. Is it possible to use a filter or RegEx as "*.csv"? Thanks in advance,

                  推荐答案

                  是否可以将过滤器或 RegEx 用作*.csv"?

                  Is it possible to use a filter or RegEx as "*.csv"?

                  没有.

                  虽然可以通过将文件和目录从文件系统映射到 URL,生成 URL,但 URL 不是目录.

                  While URLs can be generated by mapping files and directories from a filesystem to URLs, a URL isn't a directory.

                  没有办法glob URL.

                  您可以确保服务器在请求 ./ 时返回一个 URL 列表,然后使用客户端 JS 对其进行解析和过滤,然后请求每个 URL(可能使用 Promise.all 来确定您何时对这些请求中的每一个都有响应).

                  You could ensure that the server, when asked for ./ returns a list of URLs and then parse and filter it with client-side JS, and then request each of those URLs (probably using Promise.all to determine when you had a response for every one of those requests).

                  您还可以编写服务器端代码来连接所有 CSV 数据,这样您只需发出一个请求.

                  You could also write server-side code to concatenate all the CSV data so you only have to make one request.

                  这篇关于从多个 csv 文件中绘制网站中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:我应该在这个 Google Script GET 请求中使用 .getContentText() 吗? 下一篇:Javascript - 获取

                  相关文章

                    <bdo id='szHO3'></bdo><ul id='szHO3'></ul>
                • <small id='szHO3'></small><noframes id='szHO3'>

                  <legend id='szHO3'><style id='szHO3'><dir id='szHO3'><q id='szHO3'></q></dir></style></legend>

                    1. <tfoot id='szHO3'></tfoot>
                    2. <i id='szHO3'><tr id='szHO3'><dt id='szHO3'><q id='szHO3'><span id='szHO3'><b id='szHO3'><form id='szHO3'><ins id='szHO3'></ins><ul id='szHO3'></ul><sub id='szHO3'></sub></form><legend id='szHO3'></legend><bdo id='szHO3'><pre id='szHO3'><center id='szHO3'></center></pre></bdo></b><th id='szHO3'></th></span></q></dt></tr></i><div id='szHO3'><tfoot id='szHO3'></tfoot><dl id='szHO3'><fieldset id='szHO3'></fieldset></dl></div>