---
title: "Create an xyLine chart using the SQL macro"
canonical: "https://support.appfire.com/space/SUPPORT/89134229/Create%20an%20xyLine%20chart%20using%20the%20SQL%20macro"
format: markdown
---
## <span style="color: #000000">Scenario</span>

> Macro (div)
> 
> > Macro (inline-media-image)
> 
>  <span style="color: #999999">Estimated Time: 11</span>**<span style="color: #999999"> min</span>**<span style="color: #999999"> </span>

<span style="color: #000000">As an example, let's create an xyLine chart to display "Books Printed vs. Sold" for the first 24 months in circulation. </span>

## <span style="color: #000000">Background</span>

<span style="color: #000000">Our scenario uses a</span><span style="color: #091e42"> </span>data source profile<span style="color: #000000">, </span>*<span style="color: #000000">BookWarehouse,</span>*<span style="color: #000000"> to query a rollup database table, </span>*<span style="color: #000000">CIRCULATION</span>*<span style="color: #000000">. The table contains aggregate metadata associated with the circulation of books which are rolled-up and reported on by year. </span>

<span style="color: #000000">For this scenario, we focus on charting print vs. sold totals for the book "Nineteen Eighty-Four" in it's first year of circulation (1949):</span>

```sql
SQL > SELECT * FROM circulation WHERE book_id =24 and year=1949;
+---------+---------+----------+-----------+-----------+-----------+
|type    | 6_months | 12_months | 18_months | 24_months | year |
+---------+---------+----------+-----------+-----------+-----------+
|Printed |  8500.00 |  12000.00 |  20000.00 |  25000.00 | 1949 |
|Sold    |  9340.00 |  19000.00 |  14000.00 |  27000.00 | 1949 |
+---------+---------+----------+-----------+-----------+-----------+
```

> ℹ️ <span style="color: #000000">For more information about data source profiles, click the appropriate version:</span>
> ℹ️ 
> ℹ️ - [Data source profiles for 10.x version](https://appfire.atlassian.net/wiki/spaces/SQL/pages/74321547/Configure+Data+Source+Profiles+-+10.x)
> ℹ️ - [Data source profiles for 8.x version](https://appfire.atlassian.net/wiki/spaces/SQL/pages/74322923/Data+Source+Profiles+-+8.x)

<span style="color: #000000">Our query against the </span>*<span style="color: #000000">CIRCULATION</span>*<span style="color: #000000"> table looks like:</span>

```sql
SELECT type as "Statistic Type"
,format(6_months,0) as "6"
,format(12_months,0) as "12"
,format(18_months,0) as "18"
,format(24_months,0) as "24" 
FROM circulation where year='1949' 
 AND type='Printed'
UNION
SELECT type as "Statistic Type"
,format(6_months,0) as "6"
,format(12_months,0) as "12"
,format(18_months,0) as "18"
,format(24_months,0) as "24" 
FROM circulation where year='1949' 
 AND type='Sold';
```

## <span style="color: #000000">Steps</span>

<span style="color: #000000">The following steps demonstrate how to use Markup to insert Confluence's native</span><span style="color: #091e42"> </span>[Chart macro](https://confluence.atlassian.com/doc/chart-macro-163415075.html)<span style="color: #091e42"> </span><span style="color: #000000">and our</span><span style="color: #091e42"> </span>[<span style="color: #091e42">SQL macro</span>](https://appfire.atlassian.net/wiki/spaces/SQL/pages/74321601/SQL+-+10.x) <span style="color: #000000">on a Confluence page:</span>

> Macro (table-plus)
> 
> |  |  |  |
> | --- | --- | --- |
> | ![image](media://05c83e8e-3df9-4c69-a81b-4eae1bb57a3a) | ## <span style="color: #000000">Create a Confluence page</span><br><span style="color: #000000">Create a Confluence page to create the macros needed to produce the chart.</span><br>1. <span style="color: #000000">Create a page named </span>*<span style="color: #000000">Books in Circulation</span>*<span style="color: #000000"> in a space accessible to the intended audience.</span>
> 2. <span style="color: #000000">Click </span>*<span style="color: #000000">Save</span>*<span style="color: #000000"> to close the </span>*<span style="color: #000000">Page Restrictions</span>*<span style="color: #000000"> screen.</span>
> 3. <span style="color: #000000">Click </span>*<span style="color: #000000">Save</span>*<span style="color: #000000"> to save to publish the new page.</span> |  |
> | --- |
> | ![image](media://19775c22-9a18-439c-8e92-9ffa9a58c099) | ## <span style="color: #000000">Configure the Chart macro</span><br><span style="color: #000000">Edit the </span>*<span style="color: #000000">Books in Circulation</span>*<span style="color: #000000"> page and perform the following:</span><br>1. <span style="color: #000000">Insert the </span>*<span style="color: #000000">Chart</span>*<span style="color: #000000"> macro.</span>
> 2. <span style="color: #000000">Click the </span>*<span style="color: #000000">Chart</span>*<span style="color: #000000"> macro container and click </span>*<span style="color: #000000">Edit</span>*<span style="color: #000000"> so you can adjust its parameters as shown on the right. The following parameters indicate:</span>
>   - *<span style="color: #000000">Type</span>*<span style="color: #000000"> - type of a chart.</span>
>   - *<span style="color: #000000">Width</span>*<span style="color: #000000"> - width of the chart in pixels.</span>
>   - *<span style="color: #000000">Height</span>*<span style="color: #000000"> - height of the chart in pixels.</span>
>   - *<span style="color: #000000">Chart Title</span>*<span style="color: #000000"> - title for the chart.</span>
>   - *<span style="color: #000000">Chart Subtitle</span>*<span style="color: #000000"> - subtitle for the chart.</span>
>   - *<span style="color: #000000">Show legend</span>*<span style="color: #000000"> - displays the name associated with the colored bars rendered.</span>
> 3. <span style="color: #000000">Click </span>*<span style="color: #000000">Save</span>*<span style="color: #000000"> to save your changes to the macro's parameters.</span> | **<span style="color: #000000">Chart macro parameters:</span>**<br>> Macro (nested-table) |
> | --- |
> | ![image](media://999c4aab-72fe-4774-ae55-bfe16099dfd5) | ## <span style="color: #000000">Configure the SQL Query macro</span><br><span style="color: #000000">This step uses the</span> [<span style="color: #091e42">SQL macro</span>](https://appfire.atlassian.net/wiki/spaces/SQL/pages/74321601/SQL+-+10.x) <span style="color: #000000">to retrieve the data to be displayed in the bar chart. To configure the </span>*<span style="color: #000000">SQL</span>*<span style="color: #000000"> macro, do the following:</span><br>1. <span style="color: #000000">Edit your </span>*<span style="color: #000000">Books in Circulation</span>*<span style="color: #000000"> page.</span>
> 2. <span style="color: #000000">Add a line below your </span>*<span style="color: #000000">Chart</span>*<span style="color: #000000"> macro.</span>
> 3. <span style="color: #000000">Using Markup, insert a new </span>*<span style="color: #000000">SQL</span>*<span style="color: #000000"> macro on the page (more on</span><span style="color: #333333"> </span>[Markup here](https://appfire.atlassian.net/wiki/spaces/SQL/pages/74321497/Using+the+SQL+Macro+with+Markup+-+10.x)<span style="color: #000000">).</span>
> 4. <span style="color: #000000">Adjust its parameters as shown on the right. The following parameters indicate:</span>
>   - *<span style="color: #000000">Data source profile</span>*<span style="color: #000000">- name of the data source profile that you set up.</span>
>   - *<span style="color: #000000">Use database column labels </span>*<span style="color: #000000">- usage of the column names defined within the SELECT statement (e.g., Publisher, M Rev.) rather than the columns names defined within the database table(s) themselves.</span>
>   - *<span style="color: #000000">Show error if there are no rows</span>*<span style="color: #000000"> - displays an error if no rows are returned in the result set of the SQL query.</span>
>   - *<span style="color: #000000">Text to display when there are no rows</span>*<span style="color: #000000"> - text of the error message to be displayed when no rows are returned in the result set of the SQL query.</span>
> 5. <span style="color: #000000">Click </span>*<span style="color: #000000">Save</span>*<span style="color: #000000"> to save your changes to the </span>*<span style="color: #000000">SQL</span>*<span style="color: #000000"> macro's parameters.</span>
> 6. <span style="color: #000000">With the cursor positioned inside the </span>*<span style="color: #000000">SQL</span>*<span style="color: #000000"> macro container, paste in this SQL statement:</span>
>   
> 7. <span style="color: #000000">Using your mouse, "drag" the </span>*<span style="color: #000000">SQL</span>*<span style="color: #000000"> macro container into your </span>*<span style="color: #000000">Chart</span>*<span style="color: #000000"> macro container (see right).</span> | **<span style="color: #000000">SQL macro parameters:</span>**<br>> Macro (nested-table)<br>**<span style="color: #000000">Moving the </span>*****<span style="color: #000000">SQL</span>*****<span style="color: #000000"> macro inside the </span>*****<span style="color: #000000">Chart</span>*****<span style="color: #000000"> macro:</span>**<br>![image](media://4637d951-e961-42a6-a6e6-5c27b0a72303) |
> | --- |
> | ![image](media://02b52d4e-d69f-45a9-b181-454d992c8127) | ## <span style="color: #000000">Save and test the page</span><br><span style="color: #000000">Now, go back to the </span>*<span style="color: #000000">Books in Circulation</span>*<span style="color: #000000"> page and click </span>**<span style="color: #000000">Save</span>**<span style="color: #000000">. You should now see a page that appears as shown on the right. </span> | **<span style="color: #000000">Books in Circulation:</span>**<br>![image](media://d65faed8-3adb-4f2c-9ce0-3c557cd61f70) |