Write a question about a tab of your spreadsheet and get back a chart of the numbers already in it, recorded on your answers tab.
Uses
Google Sheets
OpenAIQuickChart
Ask a question about your sheet, get a chart back
Give it a link to your spreadsheet, the tab holding the data and a plain question about it, then run it whenever you want a chart. The column headings and one example row are read, the AI is asked which column holds the labels, which holds the numbers and whether a bar, line or pie chart suits the question, and the chart is drawn from the figures already in the tab.
You end up with a permanent link to the chart image, recorded as one new row on your answers tab alongside the date, the question, the chart type, the columns used and how many points were plotted. Your data is only ever read. The columns chosen must exist on the tab and be headed as expected, or the run stops rather than plotting the wrong figures. A cell that cannot be read as a number is left off and counted, and that count is written next to the chart, so no value is guessed and no gap is hidden.
Before the first run you need a tab whose first row holds the column headings, and an existing tab to record answers on.
spreadsheetUrl to blank.Set spreadsheetUrl to blank.dataTabName to blank.Set dataTabName to blank.question to blank.Set question to blank.answerTabName to Chart answers.Set answerTabName to Chart answers.maxPointsOnChart to 24.Set maxPointsOnChart to 24.spreadsheetUrl. Save it as tab.Read the rows of spreadsheetUrl. Save it as tab.headings to tab.headers.Set headings to tab.headers.tab.rows to text and save it as sampleRow.Convert the first item of tab.rows to text and save it as sampleRow.headings is emptyIf headings is emptypromptIntro to You are choosing what to plot from one spreadsheet tab so that one question can be answered as a chart.Set promptIntro to You are choosing what to plot from one spreadsheet tab so that one question can be answered as a chart.
The question: question
The tab's column headings: headings joined by , .prompt to promptIntroSet prompt to promptIntro
One example row: sampleRow
Answer with exactly one line, in this form:
label column ||| value column ||| chart type
Use the column headings exactly as they are written above - do not invent a column, rename one, or answer with a column that is not listed. The value column must be the one holding the numbers to plot. The chart type must be one of bar, line or pie. Write nothing else.answerText to blank.Set answerText to blank.chooseErrorIf a step below fails, save the error as chooseErroranswerText.Trim the response text from the OpenAI “Ask OpenAI” step and save it as answerText.The step that chooses the columns did not answer this run..Show in the output: The step that chooses the columns did not answer this run..answerText is emptyIf answerText is emptyanswerText by ||| and save it as choice.Split answerText by ||| and save it as choice.choice is less than 3If the length of choice is less than 3answerText truncated to 120 characters.Stop and report a problem: The columns to chart could not be read from this answer: answerText truncated to 120 characters.choice and save it as labelColumn.Trim the first item of choice and save it as labelColumn.choice[1] and save it as valueColumn.Trim choice[1] and save it as valueColumn.choice lowercase and save it as chartType.Make the last item of choice lowercase and save it as chartType.headings doesn't contain labelColumnIf headings doesn't contain labelColumnheadings joined by , .Stop and report a problem: There is no column headed '@labelColumn' on that tab. Its columns are: headings joined by , .headings doesn't contain valueColumnIf headings doesn't contain valueColumnheadings joined by , .Stop and report a problem: There is no column headed '@valueColumn' on that tab. Its columns are: headings joined by , .labelColumn in headings and save it as labelIndex.Find the position of labelColumn in headings and save it as labelIndex.valueColumn in headings and save it as valueIndex.Find the position of valueColumn in headings and save it as valueIndex.labelIndex is greater than 25 or valueIndex is greater than 25If labelIndex is greater than 25 or valueIndex is greater than 25columnLetters to [A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z].Set columnLetters to [A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z].labelLetter to columnLetters[@labelIndex].Set labelLetter to columnLetters[@labelIndex].valueLetter to columnLetters[@valueIndex].Set valueLetter to columnLetters[@valueIndex].labelCells to the values from the Google Sheets “Read column” step.Set labelCells to the values from the Google Sheets “Read column” step.valueCells to the values from the Google Sheets “Read column” step.Set valueCells to the values from the Google Sheets “Read column” step.labelCells is not labelColumn or the first item of…If the first item of labelCells is not labelColumn or the first item of…labelLetter is headed 'the first item of labelCells' and column valueLetter is headed 'the first item of valueCells', which is not what was chosen. Nothing was charted.Stop and report a problem: Column labelLetter is headed 'the first item of labelCells' and column valueLetter is headed 'the first item of valueCells', which is not what was chosen. Nothing was charted.chartLabels to an empty list.Set chartLabels to an empty list.chartValues to an empty list.Set chartValues to an empty list.valuesSkipped to 0.Set valuesSkipped to 0.cursor to -1.Set cursor to -1.labelCell in labelCells:For each labelCell in labelCells:cursor.Add 1 to cursor.cursor is 0If cursor is 0chartLabels is greater than or equal to maxPointsOnChart…If the length of chartLabels is greater than or equal to maxPointsOnChart…labelCell and save it as labelRaw.Trim labelCell and save it as labelRaw.labelRaw is empty or labelRaw is nullIf labelRaw is empty or labelRaw is nulllabelRaw with , replaced by with , replaced by and save it as labelClean.Trim labelRaw with , replaced by with , replaced by and save it as labelClean.labelClean is emptyIf labelClean is emptyvalueCells[@cursor] and save it as valueRaw.Trim valueCells[@cursor] and save it as valueRaw.valueRaw is empty or valueRaw is nullIf valueRaw is empty or valueRaw is nullvaluesSkipped.Add 1 to valuesSkipped.valueRaw and save it as valueNumber.Extract the first number from valueRaw and save it as valueNumber.valueNumber is blankIf valueNumber is blankvaluesSkipped.Add 1 to valuesSkipped.labelClean to the end of chartLabels and save it as chartLabels.Add labelClean to the end of chartLabels and save it as chartLabels.valueNumber to the end of chartValues and save it as chartValues.Add valueNumber to the end of chartValues and save it as chartValues.chartLabels is emptyIf chartLabels is emptychartLabels with , and save it as labelsText.Join chartLabels with , and save it as labelsText.chartValues with , and save it as valuesText.Join chartValues with , and save it as valuesText.question to 90 characters and save it as chartTitle.Shorten question to 90 characters and save it as chartTitle.chartUrl to blank.Set chartUrl to blank.chartType is pieIf chartType is piechartUrl.Trim the url from the QuickChart “Create pie chart” step and save it as chartUrl.chartUrl.Trim the url from the QuickChart “Create line chart” step and save it as chartUrl.chartUrl.Trim the url from the QuickChart “Create bar chart” step and save it as chartUrl.chartUrl doesn't start with https:// (ignoring case)If chartUrl doesn't start with https:// (ignoring case)skippedNote to blank.Set skippedNote to blank.valuesSkipped is greater than 0If valuesSkipped is greater than 0skippedNote to valuesSkipped row(s) were left off the chart because their value could not be read as a number.Change skippedNote to valuesSkipped row(s) were left off the chart because their value could not be read as a number.answerTabName in spreadsheetUrl.Add a row to answerTabName in spreadsheetUrl.chartUrl skippedNote.Show in the output: Chart: chartUrl skippedNote.