---
title: "Create a Bar chart using SQL macro"
canonical: "https://support.appfire.com/space/SUPPORT/89134751/Create%20a%20Bar%20chart%20using%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 a 3-D bar chart to display the top publishers by revenue (in $M). </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 database table, </span>*<span style="color: #000000">PUBLISHERS</span>*<span style="color: #000000">. The table contains the following columns and rows:</span>

```sql
SQL > select * from publishers;
+----+------+-------------------+-----------------+---------+
| id | rank | parent_company    | company_name    | revenue |
+----+------+-------------------+-----------------+---------+
| 10 | 1    | Pearson           | Pearson         | 5000.00 |
| 11 | 2    | Reed              | RELXGroup       | 4900.00 |
| 12 | 3    | WoodbridgeCompany | ThompsonReuters | 4700.00 |
| 13 | 4    | BertelsmannAG-NV  | Bertelsmann     | 4500.00 |
| 14 | 5    | WoltersKluwer     | WoltersKluwer   | 4100.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">PUBLISHERS</span>*<span style="color: #000000"> table looks like:</span>

```sql
SELECT company_name as "Publisher", CONCAT('$',format(revenue,0)) as "M Rev" FROM publishers ORDER BY rank asc;
```

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

<span style="color: #000000">The following steps demonstrate how to use Markup to insert Confluence's native</span> [Chart Macro](https://confluence.atlassian.com/doc/chart-macro-163415075.html) <span style="color: #000000">and our</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://7dfdcfcd-ce51-4153-8991-7245412480a7) | ## <span style="color: #000000">Create a Confluence page</span><br><span style="color: #000000">Create a Confluence page that contains the macros needed to produce the chart.</span><br>1. <span style="color: #000000">Create a page named </span>*<span style="color: #000000">Top Publishers Worldwide</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://f975604d-ff8a-4a69-9248-e777c4756434) | ## <span style="color: #000000">Configure the Chart macro</span><br><span style="color: #000000">Edit the </span>*<span style="color: #000000">Top Publishers Worldwid</span>***<span style="color: #000000">e</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. 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">Display rendered data</span>*<span style="color: #000000"> - a data table should be displayed after (below) the chart.</span>
>   - *<span style="color: #000000">Chart Title</span>*<span style="color: #000000"> - title for the chart.</span>
>   - *<span style="color: #000000">Show in 3-D</span>*<span style="color: #000000"> - add dimension to the bars within the chart.</span>
>   - *<span style="color: #000000">Opacity</span>*<span style="color: #000000"> - recommended when using 3-D and for bar the recommendation is 75%.</span>
>   - *<span style="color: #000000">Horizontal-axis</span>*<span style="color: #000000"> - column values rendered on the horizon line.</span>
>   - *<span style="color: #000000">Vertical-axis</span>*<span style="color: #000000"> - column values rendered on the vertical line.</span>
>   - *<span style="color: #000000">Show legend</span>*<span style="color: #000000"> - 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://f0775689-6472-4f7e-9ab6-13b92452fad7) | ## <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">Top Publishers Worldwide</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 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">Paste the SQL statement in </span>***<span style="color: #000000">SQL settings > SQL statement > SQL statement </span>***<span style="color: #000000">(10.x) or</span> <span style="color: #000000">inside the </span>*<span style="color: #000000">SQL</span>*<span style="color: #000000"> macro container (8.x) as:</span>
> 7. <span style="color: #000000">Use your mouse to 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</span>*****<span style="color: #000000"> 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://ab592b16-a04a-47d5-912b-c9c3917a5379) |
> | --- |
> | ![image](media://2bb5386c-76f0-4908-9216-dc9a4ddcf99d) | ## <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">Top Publishers Worldwide</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">Top Publishers by Revenue (in $M):</span>**<br>![image](media://cd243240-3129-45b7-9444-0bd178f2bda9) |