Downloads

Chart lab: turn a SQL query into a chart

Pick a business question or write your own SELECT, run it on the sample databases, and see the result as a chart, a table and the SQL.

2SQL enginesSQL Server and MariaDB
Read-onlyqueriesSELECT only, nothing changes
Ctrl+Enter also runs it. Read-only.

How it works

  1. Pick a question

    Choose a ready business question or write your own SELECT.

  2. Run it

    The query runs on the sample database you choose, on SQL Server or MariaDB.

  3. Read the chart

    Check the chart, the table and the SQL, then copy the SQL for your own use.

What the chart lab does

Pick one of the business questions, or write your own SELECT, and the lab runs it against a free sample database. You get the result three ways: a chart that fits the shape of the data, the table of rows, and the SQL itself. Every question is available in both SQL Server and MariaDB syntax, so you can switch engines and compare.

The chart type is chosen for you. A month or quarter column gives a line. A category with a number gives columns or bars. Two numbers give a scatter, and one number with many rows gives a histogram. Use the buttons above the chart to switch to another type that fits the same data.

How to read each chart

Columns and bars compare categories. Lengths start at zero, so the sizes compare directly. Lines and areas show change over an ordered list, usually time. Donuts show shares of a whole for a handful of parts. Histograms show how values spread across ranges. Scatter plots place each item by two measures. Waterfalls bridge a starting total to an ending total through each step. Heatmaps colour a grid of categories against periods, darker for larger values.

Hover over a mark, or use the keyboard: Tab to the chart, then the arrow keys move from point to point and Escape clears the tip. Click a legend item to hide a series. Download SVG saves the picture, and Copy data as CSV copies the numbers behind it.

Questions and answers

Why does a preset's insight not match the numbers I see?

The sample dates move forward every day, so a month or a week in the sample is a different set of rows over time. The "What to notice" sentences describe the shape of each result, such as which category leads or where the peaks fall, so they stay true as the dates change. Totals that do not depend on dates, such as the all-time customer ranking, stay the same.

Can I use my own query?

Yes. Choose "Write your own SELECT" and type one query. The lab accepts a single read-only SELECT (a WITH clause is fine). The server refuses writes and more than one statement. Pick the sample database the query uses, and use the schema prefix that engine expects.

Why are the SQL Server and MariaDB numbers different for contoso?

The two engines hold different copies of the sample. Compare the shape of the chart across engines rather than the exact totals, unless the database is the same on both sides.

Why is there no link to open the query in the SQL editor?

The SQL editor opens a database, not a query, so the lab cannot pass your SQL to it. Copy the SQL and paste it into the editor instead.

Can I embed a chart in my own page?

The chart library is public as LSCharts.render(element, spec) in charts.js. Give it a column list and rows, and it draws the chart in light and dark themes with a table for screen readers.

More tools: all tools · function reference · guides