I had similar question when I started learning Prometheus.
First thing to note, Prometheus expression language evaluates to four types.
- strings
- scalars
- instant vectors
- range vectors
(Instant vectors vs range vectors is very well explained in the resources I have linked below.)
Prometheus HTTP API's have two types,
- instant queries - API returns single value for the given evaluation time
- range queries - API returns multiple values based on time range and step
When querying through the Prometheus UI, results can be represented as either table or graph.
If you inspect the API call made from the Prometheus UI, you will notice that
- queries displaying data in the table will hit the instant query endpoint
- queries displaying data in the graph will hit the range query endpoint
This results in four combinations:
Query returning instant vector (via instant query API endpoint)

Query returning instant vector (via range query API endpoint)
When we switch from table to graph view, Prometheus UI calls range query endpoint. Range query endpoint is essentially just syntactic sugar for running a series of instant queries. This endpoint makes it easy to visualize/graph time series.
If the range query endpoint didn't exist, multiple instant query calls would have to be made in order to generate a graph for a certain time period.

step (seconds) in the API call decide how many values should be fetched. (obviously the highest possible resolution here depends on the scrape interval).
step=2 means between those two timestamps please give us a value for every second.
Query returning range vector (via instant query API endpoint)

Query returning range vector (via range query API endpoint)
Fails with error "Error executing query: invalid expression type "range vector" for range query, must be Scalar or instant Vector
"

You can't directly graph a range vector output, since it would produce multiple output points for each series at each resolution step in the graph. Also, it's not guaranteed that every element in a vector will have the same number of samples for a given range.
Resources to learn
To learn more on this, refer below resources that I found extremely useful