How data should be formatted for a given graph?

Note: this is a beginner generic question to better understand the kind of actions I can take with my data. I used so far Kibana, SQL and developed my own graphs with Highcharts.

I connected Grafana to an SQLite file and to an Elasticsearch instance.

I noticed that what is required on the SQL part is a query that does the processing of the data and provides a table to graph. Something like the following to get the top 10 cities with a specific event

select
  CITY,
  count(CITY)
from consolidated_results
group by CITY
order by count(CITY) desc
limit 10

This is a good input to a bar chart, but not to a pie one for instance.

Should I have a similar approach to Elasticsearch? That is: to build a query that will output the data formatted in a “table” so that it can be readily plotted?

And generally: should the query to a data source always send back data formatted for a specific chart type? (or is Grafana also doing processing of the received data to format it for a chart? via a Transform? )

Not necessarily, some data lends itself to more than one grafana visualization type. The answer is it depends on your requirements. Like the following data cannot be plotted on a time series because it does not have a time column

Yes, I understand that (and this is a good thing because all data is not time based).

My point was rather about whether the data provided to Graphana (to a specific graph) is expected to be formatted a certain way. And whether that way depends on the source (say, SQL vs Elasticsearch - one will give a table, the other a JSON with an array).

In other words - whether the data from a source must be queried in a specific way to be able to be displayed. The bonus question would be: where is that format documented (probably per chart)