This page was written because Joe asked in the API user-supported group how to use data from a CSV file.
How to import data from a CSV doesn't seem well documented in the API or anywhere else. For example Stack Overflow has years old posts involving external libraries such as jquery.csv.js in posts such as How to use Google Chart with data from a csv, Create Google Chart from CSV input, and How to use a csv file with the google chart API?
The API documentation has Using an External Data Store which talks about using CsvDataSourceServlets while Reading CSV Files gets close to the solution but does not provide the full code. Also close is the thread Using CSV file to Populate DataTable in the API user-supported group.
Using the last group, I finally got it.
The method is similar to the query used to get data from a Google Sheet that I use frequently.
Here a graph using data imported from a CSV file:
A div with the id of "csv-div" was created in the HTML
This is the CSV file:
Day,Status A,Status B,Status C
The preferred date format in CSV files is yyyy-MM-dd (for example 2023-05-06) and for time is hh:mm:ss. (for example 11:29:32.352.)
If you try to use a CSV file with a date format using for example csvColumns: ['date', 'number'], in the calling query that the API does not understand such as dd-MM-yyyy (for example - 05-06-2023) you will get a warning saying that ".getTimezoneOffset is not a function".
Wrong date/time format error message