SELECT Date, Temp FROM ggsql:airquality
VISUALISE Date AS x, Temp AS y
DRAW line
SCALE x VIA date
LABEL
title => 'Daily Temperature',
x => 'Date',
y => 'Temperature (F)'Line chart
basic
line
time-series
Time series visualization with proper date scaling
Line charts are ideal for showing trends over time. The SCALE x VIA date clause ensures proper date formatting on the axis.
Code
Explanation
SELECT ... FROM ggsql:airqualityqueries the built-in air quality datasetVISUALISE Date AS x, Temp AS ymaps the date column to x and temperature to yDRAW lineconnects data points with linesSCALE x VIA dateensures the x-axis is formatted as dates with appropriate tick marks (happens automatically if your database has a dedicated date type)LABELprovides descriptive titles for the chart and axes
Variations
Multiple lines by category
Here we show the temperature by day instead, and split the lines by month. Since month is encoded as an integer it doesn’t automatically split the lines, and we have to use an explicit ordinal scale for it (see what happens if you remove that).
SELECT Day, Temp, Month FROM ggsql:airquality
VISUALISE Day AS x, Temp AS y, Month AS color
DRAW line
SCALE ORDINAL color
LABEL
title => 'Daily Temperature by Month',
x => 'Date',
y => 'Temperature (F)'