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

<span style="color: #000000">As an example, let's create a Pie chart to display "Book Print Operational Costs". </span>

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

<span style="color: #000000">Our scenario uses a</span><span style="color: #091e42"> </span><span style="color: #000000">data source profile, </span>*<span style="color: #000000">BookWarehouse</span>*<span style="color: #000000">, to query a database table, </span>*<span style="color: #000000">PRINTOPERATION</span>*<span style="color: #000000">. The table contains current minimum, maximum, and, average operational costs associated with the printing and go-to-market costs for books. </span>

<span style="color: #000000">For this scenario, we focus on charting the current average market costs for each type of print operation.</span>

```sql
SQL > mysql> select po_book_id, printoperation, avgcost from printoperation;
+------------+-----------------------+----------+
| po_book_id | printoperation        | avgcost  |
+------------+-----------------------+----------+
|          2 | Developmental Editing | 18000.00 |
|          3 | Copyediting           |  7000.00 |
|          4 | Cover Design          |  3500.00 |
|          5 | Formatting            |  2500.00 |
|          6 | Illustrations         |  4000.00 |
|          7 | ISBN Registration     |   250.00 |
|          8 | Marketing & PR        |  5000.00 |
+------------+-----------------------+----------+

```

> ℹ️ <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">PRINTOPERATION</span>*<span style="color: #000000"> table looks like:</span>

```sql
SELECT printoperation as "Service"
,format(avgcost,0) AS "Cost" 
FROM printoperation;
```

## <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>[SQL macro](https://appfire.atlassian.net/wiki/spaces/SQL/pages/74321601/SQL+macro+-+10.x) <span style="color: #000000">on a Confluence page:</span>

> Macro (table-plus)
> 
> |  |  |  |
> | --- | --- | --- |
> | ![image](media://8c005491-9499-4f90-9998-67881d045085) | ## <span style="color: #000000">Create a Confluence page</span><br><span style="color: #000000">Create a Confluence page to add the macros needed to produce the chart.</span><br>1. <span style="color: #000000">Create a page named </span>*<span style="color: #000000">Print Operations</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://2646c3a1-305b-47fd-8d58-f6f827a76d89) | ## <span style="color: #000000">Configure the Chart macro</span><br><span style="color: #000000">Edit the </span>*<span style="color: #000000">Print Operations</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 modify 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">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">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://4718c681-0dbe-4ed3-9fb8-16b48e52be48) | ## <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/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">Print Operations</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 resultset 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 resultset 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://0e2bff95-44f0-4f50-bd6f-2f62036e416d) |
> | --- |
> | ![image](media://baff8732-267b-46df-800d-b7450bfebcea) | ## <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">Print Operations</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">Book Print Operational Costs:</span>**<br>![image](media://a37e1b1c-c324-433f-858d-637eb21e998c) |