# Line

<table data-card-size="large" data-view="cards"><thead><tr><th data-card-target data-type="content-ref"></th><th data-hidden></th><th data-hidden></th><th data-hidden></th><th data-hidden data-card-cover data-type="files"></th></tr></thead><tbody><tr><td><a href="/pages/TrmnxOWEJwPgBgA1C5c4#basic-line-chart">/pages/TrmnxOWEJwPgBgA1C5c4#basic-line-chart</a></td><td></td><td></td><td></td><td><a href="/files/EktTvLb53M96My1pNrht">/files/EktTvLb53M96My1pNrht</a></td></tr><tr><td><a href="/pages/TrmnxOWEJwPgBgA1C5c4#auto-line-chart">/pages/TrmnxOWEJwPgBgA1C5c4#auto-line-chart</a></td><td></td><td></td><td></td><td><a href="/files/CYOhrtwjeY64w59igrmb">/files/CYOhrtwjeY64w59igrmb</a></td></tr><tr><td><a href="/pages/TrmnxOWEJwPgBgA1C5c4#line-with-series-title-spacing">/pages/TrmnxOWEJwPgBgA1C5c4#line-with-series-title-spacing</a></td><td></td><td></td><td></td><td><a href="/files/ohM17AOfhRsjCOFl01Zn">/files/ohM17AOfhRsjCOFl01Zn</a></td></tr><tr><td><a href="/pages/TrmnxOWEJwPgBgA1C5c4#manual-category-and-series-line">/pages/TrmnxOWEJwPgBgA1C5c4#manual-category-and-series-line</a></td><td></td><td></td><td></td><td><a href="/files/aj0JbWvVDdCptdwlT5aF">/files/aj0JbWvVDdCptdwlT5aF</a></td></tr></tbody></table>

## Basic Line Chart

```sql
-- @chart: Line
-- @title: Line - Simple Line Chart
-- @subtitle: An example line chart with a detected category and series
-- @formats: currency
SELECT
	TRUNC(date_closed, 'MONTH') as Month,
	sum(amount) as Sales
FROM sales
GROUP BY Month
ORDER BY Month ASC;
```

<figure><img src="/files/EktTvLb53M96My1pNrht" alt=""><figcaption><p>An example date line chart </p></figcaption></figure>

| MONTH                            | SALES     |
| -------------------------------- | --------- |
| January, 01 2017 00:00:00 +0000  | 2668855.0 |
| February, 01 2017 00:00:00 +0000 | 3951547.0 |
| March, 01 2017 00:00:00 +0000    | 4403443.0 |
| April, 01 2017 00:00:00 +0000    | 3079040.0 |
| May, 01 2017 00:00:00 +0000      | 2576305.0 |
| June, 01 2017 00:00:00 +0000     | 3100093.0 |
| July, 01 2017 00:00:00 +0000     | 3112476.0 |

## Auto Line Chart

```sql
-- @title: Auto Line - Auto Generated Date Line Chart
-- @subtitle: An example chart which is auto detected to be a line
-- @formats: currency
SELECT 
	TRUNC(date_closed, 'MONTH') as Month,
	sum(amount) as Sales
FROM sales
GROUP BY Month
ORDER BY Month ASC;
```

<figure><img src="/files/CYOhrtwjeY64w59igrmb" alt=""><figcaption><p>Example auto line chart</p></figcaption></figure>

| MONTH                            | SALES     |
| -------------------------------- | --------- |
| January, 01 2017 00:00:00 +0000  | 2668855.0 |
| February, 01 2017 00:00:00 +0000 | 3951547.0 |
| March, 01 2017 00:00:00 +0000    | 4403443.0 |
| April, 01 2017 00:00:00 +0000    | 3079040.0 |
| May, 01 2017 00:00:00 +0000      | 2576305.0 |

## Line with Series Title Spacing

```sql
-- @chart: Line
-- @title: Series Title Spacing
-- @subtitle: Spacing on series titles is determined by underscores
-- @formats: currency
SELECT
	TRUNC(date_closed, 'MONTH') as Month,
	sum(amount) as total_sales_amount
FROM sales
GROUP BY Month
ORDER BY Month ASC;
```

<figure><img src="/files/ohM17AOfhRsjCOFl01Zn" alt=""><figcaption><p>An example line chart with underscores converted to spaces in the series titles</p></figcaption></figure>

| MONTH                            | TOTAL\_SALES\_AMOUNT |
| -------------------------------- | -------------------- |
| January, 01 2017 00:00:00 +0000  | 2668855.0            |
| February, 01 2017 00:00:00 +0000 | 3951547.0            |
| March, 01 2017 00:00:00 +0000    | 4403443.0            |
| April, 01 2017 00:00:00 +0000    | 3079040.0            |
| May, 01 2017 00:00:00 +0000      | 2576305.0            |
| June, 01 2017 00:00:00 +0000     | 3100093.0            |
| July, 01 2017 00:00:00 +0000     | 3112476.0            |

## Manual @Category and @series Line

```sql
-- @chart: line
-- @title: Manual Category and Series
-- @subtitle: An example chart manually setting the category and series
-- @category: Date_Closed
-- @series: Amount
SELECT 
    Sub.*,
    (
      SELECT channel
      FROM Sales
      WHERE Sales.Date_Closed = Sub.Date_Closed
      GROUP BY Channel
      ORDER BY count(*) DESC
      LIMIT 1
    ) as TopChannel
FROM (
    SELECT 
      Date_Closed,
      sum(Amount) as Amount,
      sum(Profit) as Profit
    FROM Sales
    WHERE Status = 'Won'
    GROUP BY Date_Closed
    ORDER BY Date_Closed ASC
) as Sub;
```

<figure><img src="/files/aj0JbWvVDdCptdwlT5aF" alt=""><figcaption><p>An example chart with a manually specified @category and @series</p></figcaption></figure>

| DATE\_CLOSED                    | AMOUNT   | PROFIT  | TOPCHANNEL |
| ------------------------------- | -------- | ------- | ---------- |
| January, 02 2017 00:00:00 +0000 | 78013.0  | 13263.0 | referral   |
| January, 06 2017 00:00:00 +0000 | 130899.0 | 40938.0 | event      |
| January, 12 2017 00:00:00 +0000 | 75705.0  | 21198.0 | coldcall   |
| January, 14 2017 00:00:00 +0000 | 72732.0  | 13092.0 | event      |
| January, 17 2017 00:00:00 +0000 | 84572.0  | 27064.0 | search     |
| January, 20 2017 00:00:00 +0000 | 76878.0  | 11532.0 | event      |
| January, 31 2017 00:00:00 +0000 | 127149.0 | 49589.0 | referral   |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.chartsql.com/charts/line.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
