Sub topic 9
Creating charts from your data
This chapter covers asking Gemini in Google Sheets to build a chart from a data range. It assumes you can open the Gemini side panel and that your sheet follows the layout rules from earlier chapters: a header row, one record per row, and one data type per column. It also assumes you can write a simple formula such as SUMIF. Chart refinement and the full verification routine get their own chapters, so this chapter only previews them.
What Gemini does when you ask for a chart
When you ask for a chart, Gemini does the same work you would do in the chart editor. It picks a chart type, chooses the range, assigns columns to the horizontal axis and to the series, and inserts a chart object into the sheet. You get a normal Google Sheets chart. You can open the chart editor and change any setting by hand.
Gemini is not producing an image, and it is not computing a separate result. The chart is a view of cells in your sheet. If Gemini picks the wrong range or the wrong grouping, the chart will look plausible and still be wrong. This is why the prompt and the verification step matter more for charts than they might seem to.
The usual flow looks like this:
Prepare the range first
Gemini reads your sheet the way a person scanning it would. Anything that confuses a person will confuse it too. Before you ask for a chart, check these points:
- The first row of the range holds short, unique column headers.
- Each column holds one kind of value. A numeric column must contain real numbers, not text such as "$12.50 " or "12,5".
- Dates are real dates, not text that only looks like a date.
- There are no merged cells, subtotal rows, or grand-total rows inside the range.
- There are no fully blank rows or columns in the middle of the data.
A total row is the most common cause of a bad chart. If row 51 holds a grand total and your range covers A1:E51, the total becomes one more bar, and it dwarfs the real categories. Either exclude it from the range or move totals to a separate area.
A quick way to find text-numbers is to select the column. If the numbers sit on the left of their cells, or the status bar at the bottom right shows a count but no sum, they are probably text. Fix them before you prompt.
Writing a chart prompt
A good chart prompt names five things: the chart type, the measure, the grouping, the data range, and a title. Here is the example from the plan, for an expense sheet with the columns Date, Category, Description, Amount, and Paid By:
Create a column chart of total Amount by Category using the data in A1:E50, with the title "Spending by Category".Each part of the sentence closes off a decision that Gemini would otherwise make for you:
| Prompt part | What it settles | What can go wrong if you omit it |
|---|---|---|
| "column chart" | The chart type | Gemini may choose a pie or line chart that suits the data poorly |
| "total Amount" | The measure and how to combine rows | You may get one bar per row instead of one per category |
| "by Category" | The grouping column | Gemini may group by Paid By or by Date |
| "A1:E50" | The source range, including the header row | It may stop early, include blank rows, or skip a column |
| the title in quotes | The exact title text | You get a generic title that you must retype |
Use the exact header names as they appear in row 1. "Amount" is better than "how much we spent", because the header is the handle Gemini can match to a column.
If you do not know which chart type fits, describe the question and let Gemini suggest one:
I want to compare how much each person paid in each month. Suggest a chart type for the data in A1:E50 and explain why.Treat the answer as a suggestion. Then name the type in your follow-up request.
Choosing a chart type
You are the one who knows the question the chart should answer, so choose the type yourself and put it in the prompt.
| Question | Usually fits | Prompt wording |
|---|---|---|
| How do categories compare? | Column or bar chart | "column chart of total Amount by Category" |
| How does a value change over time? | Line chart | "line chart of total Amount by month" |
| What share does each part hold of a whole? | Pie chart, with few categories | "pie chart of Amount share by Category" |
| How are two numeric values related? | Scatter chart | "scatter chart of Hours (column B) against Cost (column C)" |
A pie chart with more than five or six slices is hard to read. Use a bar chart in that case. For time trends, make sure the date column holds real dates. Otherwise the horizontal axis may be treated as text labels and sorted alphabetically.
Charting raw rows or a summary table
There are two ways to get "total by category" onto a chart.
- Chart the raw rows and let the chart aggregate. The chart editor can combine rows that share a category. This keeps everything in one place, but the aggregation setting is easy to miss, and you cannot see the totals in cells.
- Chart a summary table. You build a small table of totals with a formula, then chart that table. The totals are visible in cells, which makes checking easy.
For anything you plan to share or rely on, the second way is more dependable. Ask Gemini for the summary first, or write it yourself with QUERY, as in the plan:
=QUERY(A1:E, "select B, sum(D) where D is not null group by B label sum(D) 'Total'", 1)Place this formula in an empty area, such as H1. It returns two columns: Category and Total. Then point the chart prompt at that block:
Create a column chart using the data in H1:I10, with Category on the horizontal axis and Total as the series, titled "Spending by Category".One more point about open-ended ranges. A1:E in the QUERY grows as you add rows, so the summary stays current. The chart's source range is the small block H1:I10, which does not grow if a new category appears. Leave a few spare rows in the block, or extend the range in the chart editor when the category list changes.
Reviewing what Gemini proposes
Gemini typically shows a preview or inserts the chart. Exact wording and buttons differ between releases and plans, so look for the option that inserts the result into the sheet. Before accepting, check these things:
- Chart type. It matches what you asked for.
- Range. In the chart editor, the data range matches the one you named. Look for a range that is too short or one that begins at row 2 and drops the header.
- Axis and series. Categories run along the horizontal axis. The measure is the series.
- Aggregation. Each category appears once.
- Title and axis labels. They are present and correct. Axis labels are often missing or generic.
- Number of bars or slices. It equals the number of distinct categories you expect.
If something is off, say so in a follow-up message, naming the exact fix. For example: "Use A1:E50 as the range, not A1:E30." Specific corrections work better than "make it better". Later chapters on refining charts and on follow-up prompts go into this in detail.
Common failures and their causes
| Symptom | Likely cause | Fix |
|---|---|---|
| One bar for each row, not for each category | The chart is not aggregating | Chart a summary table, or turn on aggregation in the chart editor |
| An extra huge bar labelled "Total" | A total row sits inside the range | Exclude that row from the range |
| Bars missing for some categories | Range ends too early, or a category has no numeric values | Extend the range and check the Amount cells |
| Values all show as zero or the chart is empty | Numbers are stored as text | Convert the column to real numbers |
| Dates appear in the wrong order | Dates are text, or the axis treats them as labels | Convert to real dates and set the axis type |
| Two categories that should be one, such as "Groceries" and "groceries " | Inconsistent spelling or trailing spaces | Clean the category column |
| Chart does not update with new rows | Source range is fixed | Extend the range, or use a summary table with spare rows |
The last two items deserve attention. Spelling variants are invisible in the sheet and produce separate bars. A fixed range quietly ignores new data. Neither causes an error message.
Verify the chart against a total
A chart cannot be checked by eye, so check one number. Pick one category and compute its total independently with a formula from the plan:
=SUMIF(B2:B, "Groceries", D2:D)Compare that value with the Groceries bar. Hover over the bar to see its value, or read it from the summary table if you built one. Then do one more check: add up all the bars and compare the sum with =SUM(D2:D). If the two agree, the chart includes every row exactly once. If the bar total is lower, rows were dropped. If it is higher, something was counted twice, often a total row.
Privacy note for charts
A chart prompt sends the contents of the range you name, and possibly the surrounding sheet, to Gemini so it can read the data. Do not chart ranges that contain data you are not allowed to process this way. Your organization's admin settings and plan decide how this data is handled. Check those rules before you use real customer or employee data. The final chapter covers this topic.
Exercises
Exercise
Your sheet has columns Date, Category, Description, Amount, and Paid By in A1:E50. Write a prompt that creates a bar chart of the total Amount for each person in Paid By, titled "Spending by Person". What would you check afterward?
Show answer
Prompt: Create a bar chart of total Amount by Paid By using the data in A1:E50, with the title "Spending by Person". It names the chart type, measure, grouping, range, and title. Afterward, pick one person and compute the total with =SUMIF(E2:E, "Name", D2:D), then compare it with that person's bar. Also confirm the bars add up to =SUM(D2:D) and that no person appears twice because of spelling or trailing-space differences.
Exercise
A column chart shows a bar for each of 49 rows instead of one bar per category, and a bar labelled "Total" is far taller than all the others. Name two causes and a fix for each.
Show answer
First cause: the chart is not aggregating rows by category. Fix it by charting a summary table built with QUERY or SUMIF, or by turning on aggregation in the chart editor. Second cause: a total row is inside the chart range. Fix it by shrinking the range so it ends above the total row, or by moving totals out of the data block.