4 - Creating Your Own Database (Google Sheet)
⚠️ Important Note: This page was updated significantly August 30, 2021 to fix a new problem with loading spreadsheet data.
For reference, when you want to find real-world data, consider using this resource.
1 - Create a Google Sheets File and Add Data
Create a Google Sheet file then create a simple table, like below, that could be used for a Scatter Chart. Also, name your individual sheet (the tab at the bottom) something like "myData".
x | y |
3 | 4 |
4 | 6 |
2 - Publish Your Google Sheets File
Create a Google Sheets file and publish it by selection file
>Publish to the web...
then click the Publish button.
3 - Get the Public Link for a Table
4 - Load Your Table in Javascript
Copy the code below and paste it just after this line. Now replace the link with your table link copied in the previous step and change the tab label (e.g. 'myData') to match your sheet tab label. You can change the composeMyCharts
function name as you wish or keep it the same.
Now you can access your database in your SQL statements. Remember that your individual sheet names are the tables you can select from in SQL. So if you want to get all the columns from a sheet (table) called "myData", then you would use the following:SELECT * FROM myData
5 - Create Charts from Your New Table
Create a function in your Javascript that will then define the charts for your new table. You can use the example below as a template, but you want the ensure the function name used in step 3 (e.g. composeMyCharts) matches this function name. You will also want to change the SQL and ensure that you have HTML elements with ID's to display the charts.
For any additional tables (Spreadsheet Tabs) you want to incorporate, you will repeat steps 2 through 5 above with the appropriate link, tab name, and additional function for composing charts.
Last updated