---
title: "Create an xyArea chart using the SQL macro"
canonical: "https://support.appfire.com/space/SUPPORT/89134832/Create%20an%20xyArea%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: 9</span>**<span style="color: #999999"> min</span>**<span style="color: #999999"> </span>

<span style="color: #000000">As an example, let's create an xyArea chart to display "Publishing Revenue vs. Expense" per quarter in 2017. </span>

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

<span style="color: #000000">Our scenario uses a</span> <span style="color: #000000">data source profile, </span>*<span style="color: #000000">BookWarehouse,</span>*<span style="color: #000000"> to query a rollup database table, </span>*<span style="color: #000000">PUBLICATION_RVE</span>*<span style="color: #000000">. The table contains aggregate rollup revenue and expense data by book, by quarter. </span>

<span style="color: #000000">For this scenario, we are focusing on charting 2017 revenue and expense data for a single publisher.</span>

```sql
SQL > explain publication_rve;
+--------------+------------------+------+-----+---------+----------------+
| Field        | Type             | Null | Key | Default | Extra          |
+--------------+------------------+------+-----+---------+----------------+
| publisher_id | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| type         | varchar(255)     | NO   |     | NULL    |                |
| Q1           | decimal(10,2)    | NO   |     | NULL    |                |
| Q2           | decimal(10,2)    | NO   |     | NULL    |                |
| Q3           | decimal(10,2)    | NO   |     | NULL    |                |
| Q4           | decimal(10,2)    | NO   |     | NULL    |                |
| year         | varchar(255)     | NO   |     | NULL    |                |
+--------------+------------------+------+-----+---------+----------------+
```

> ℹ️ <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">The query against the </span>*<span style="color: #000000">PUBLICATION_RVE</span>*<span style="color: #000000"> table looks like:</span>

```sql
SELECT type as "Statement Type"
,format(Q1,0) as "Q1"
,format(Q2,0) as "Q2"
,format(Q2,0) as "Q3"
,format(Q2,0) as "Q4" 
FROM publication_rve where year='2017' 
 AND type='Revenue'
UNION
SELECT type as "Statement Type"
,format(Q1,0) as "Q1"
,format(Q2,0) as "Q2"
,format(Q2,0) as "Q3"
,format(Q2,0) as "Q4" 
FROM publication_rve where year='2017' 
 AND type='Expense';
```

## <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>[SQL macro](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://becfa049-3ae7-4910-839f-8c979421b0d7) | ## <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">Publication Revenue vs. Expense</span>*<span style="color: #000000"> in a space accessible to the desired 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://10198403-f34a-4e95-9434-01568592217e) | ## <span style="color: #000000">Configure the Chart macro</span><br><span style="color: #000000">Edit the </span>*<span style="color: #000000">Publication Revenue vs. Expense</span>*<span style="color: #000000"> page and do 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.</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">Column</span>*<span style="color: #000000"> - column name or order of mapping from the query result to the chart.</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://87b4966d-8c59-4ad8-8f8d-5f3ec8340d86) | ## <span style="color: #000000">Configure the SQL Query macro</span><br><span style="color: #000000">This step uses the</span> [SQL macro](https://appfire.atlassian.net/wiki/spaces/SQL/pages/74322843) <span style="color: #000000">to retrieve the data to be displayed in the 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">Publication Revenue vs. Expense</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> [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 SQL macro inside the Chart macro:</span>**<br>![image](media://ae9ab690-e08a-49df-8582-91723de5d5b0) |
> | --- |
> | ![image](media://cc08eb95-6158-40f6-98b1-3bf236b84977) | ## <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">Publication Revenue vs. Expense</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">Final xyArea Chart:</span>**<br>![image](media://48235a8a-b55c-4856-9236-bfd969f870b6) |