参考 loadTable()

loadTable()

Reads the contents of a file or URL and creates a p5.Table object with its values. If a file is specified, it must be located in the sketch's "data" folder. The filename parameter can also be a URL to a file found online. By default, the file is assumed to be comma-separated (in CSV format). Table only looks for a header row if the 'header' option is included.

This method is asynchronous, meaning it may not finish before the next line in your sketch is executed. Calling loadTable() inside preload() guarantees to complete the operation before setup() and draw() are called. Outside of preload(), you may supply a callback function to handle the object:

All files loaded and saved use UTF-8 encoding. This method is suitable for fetching files up to size of 64MB.

示例

语法

loadTable(filename, [extension], [header], [callback], [errorCallback])

参数

filename
String:

name of the file or URL to load

extension
String:

parse the table by comma-separated values "csv", semicolon-separated values "ssv", or tab-separated values "tsv"

header
String:

"header" to indicate table has header row

callback
Function:

function to be executed after loadTable() completes. On success, the Table object is passed in as the first argument.

errorCallback
Function:

function to be executed if there is an error, response is passed in as first argument

Returns

Object: Table object containing data
Notice any errors or typos? Please let us know. Please feel free to edit src/io/files.js and open a pull request!

相关参考