Dory Docs
Workflows

Build Charts from SQL in Dory

Good charts come from clear SQL output. Dory Charts & Results can visualize query results, but the query should already express the right time column, dimension, and metric.

When to Use This Workflow

  • Your SQL works but the chart looks wrong.
  • The result has too many columns.
  • You need to turn detail rows into trends or Top-N comparisons.
  • You want AI to rewrite SQL into a chart-ready shape.
  • You need to share an analysis with the team.

1. Define the Chart Question

Decide what the chart should answer:

  • Trend: how does a metric change over time?
  • Comparison: which category is higher?
  • Share: what percentage does each part represent?
  • Distribution: where do values cluster?
  • Detail: which records need investigation?

2. Shape the Result

Chart typeRecommended resultExample columns
Line chartTime column + metricdate, revenue
Bar chartCategory + metricchannel, orders
Pie chartSmall category set + valuestatus, count
Multi-metric trendTime column + metricsdate, dau, orders
Detail tableID, time, status, key fieldsorder_id, created_at, status

3. Aggregate in SQL

SELECT
  DATE(created_at) AS date,
  COUNT(*) AS orders
FROM orders
WHERE created_at >= CURRENT_DATE - INTERVAL '30 days'
GROUP BY date
ORDER BY date;

Use the date functions for your database dialect.

4. Ask AI for Chart-Ready SQL

Rewrite the current SQL for a line chart:
- first column: date
- second column: orders
- order by date ascending
- last 30 days only
- keep the current filters

5. Validate in Charts & Results

Check the X axis, Y axis, ordering, Top-N behavior, category count, null values, and outliers.

FAQ

Why is my chart messy?

The result is usually not aggregated, has too many categories, has unclear column names, or lacks stable ordering.

When should I avoid pie charts?

Avoid pie charts when there are many categories or small differences. Use a bar chart or Top-N instead.

Why do chart values differ from table values?

The chart may be using a different aggregation level or filtered result. Confirm the SQL output, selected metric, and grouping columns before trusting the visualization.

Next Steps

On this page