# Widgets SQL queries default to displaying as a table. Other forms of display - called widgets - are also available, and are selected based on the names of the columns returned by the query. ## Bar chart: bar_label, bar_quantity A query that returns columns called `bar_label` and `bar_quantity` will be rendered as a simple bar chart, using [Vega-Lite](https://vega.github.io/vega-lite/).  Bar chart live demo: [simonwillison.net/dashboard/by-month/](https://simonwillison.net/dashboard/by-month/) SQL example: ```sql select county.name as bar_label, count(*) as bar_quantity from location join county on county.id = location.county_id group by county.name order by count(*) desc limit 10 ``` Or using a static list of values: ```sql SELECT * FROM ( VALUES (1, 'one'), (2, 'two'), (3, 'three') ) AS t (bar_quantity, bar_label); ``` ## Big number: big_number, label If you want to display the results as a big number accompanied by a label, you can do so by returning `big_number` and `label` columns from your query, for example. ```sql select 'Number of states' as label, count(*) as big_number from states; ```  Big number live demo: [simonwillison.net/dashboard/big-numbers-demo/](https://simonwillison.net/dashboard/big-numbers-demo/) ## Progress bar: completed_count, total_count To display a progress bar, return columns `total_count` and `completed_count`. ```sql select 1203 as total_count, 755 as completed_count; ``` This SQL pattern can be useful for constructing progress bars: ```sql select ( select count(*) from task ) as total_count, ( select count(*) from task where resolved_at is not null ) as completed_count ```  Progress bar live demo: [simonwillison.net/dashboard/progress-bar-demo/](https://simonwillison.net/dashboard/progress-bar-demo/) ## Word cloud: wordcloud_count, wordcloud_word To display a word cloud, return a column `wordcloud_word` containing words with a corresponding `wordcloud_count` column with the frequency of those words. This example generates word clouds for article body text: ```sql with words as ( select lower( (regexp_matches(body, '\w+', 'g'))[1] ) as word from articles ) select word as wordcloud_word, count(*) as wordcloud_count from words group by word order by count(*) desc ``` Here's a fun variant that uses PostgreSQL's built-in stemming algorithm to first remove common stop words: ```sql with words as ( select lower( (regexp_matches(to_tsvector('english', body)::text, '[a-z]+', 'g'))[1] ) as word from articles ) select word as wordcloud_word, count(*) as wordcloud_count from words group by word order by count(*) desc ```  Word cloud live demo: [simonwillison.net/dashboard/tag-cloud/](https://simonwillison.net/dashboard/tag-cloud/) ## markdown Return a single column called `markdown` to render the contents as Markdown, for example: ```sql select '# Number of states: ' || count(*) as markdown from states; ``` ## html Return a single column called `html` to render the contents directly as HTML. This HTML is filtered using [Bleach](https://github.com/mozilla/bleach) so the only tags allowed are `a[href]`, `abbr`, `acronym`, `b`, `blockquote`, `code`, `em`, `i`, `li`, `ol`, `strong`, `ul`, `pre`, `p`, `h1`, `h2`, `h3`, `h4`, `h5`, `h6`. ```sql select '
{{ row.label }}