How to create a chart with SQL - 8.x

How to create a chart with SQL - 8.x

Summary

The Chart macro combined with the SQL macro provides powerful visual reporting capabilities. These macros were designed to work together. The SQL macros produce standard Confluence tables. The Chart macro produces charts from tables included in its macro body. Of course, the parameters of the Chart macro must define a chart that can be produced from the format of the table (or tables) included in the chart macro body. So part of the challenge is to define the chart correctly to match with your table(s) produced by the SQL macros and this depends on what you are trying to do and how you have constructed the SQL. The Chart macro has a number of parameters that can be adjusted to accommodate different table arrangements. This article explains some simple examples to get started. 

Steps

Step

Description

Create a new page.

Add a Chart macro.

  • Set the chart type; this example uses a pie chart.

  • Edit other parameters as needed.

  • For this example:

    • Set Content orientation to vertical - this is required because we want to use table rows for the values.

    • Optional: Set Display rendered data as 'after'.

    • Optional: Set Pie section label to '%0% (%2%)'.

Create a small example table in the Chart macro body.

  • This is just a quick way to get the chart defined and working.

  • Use INSERT table with a few rows and columns.

  • The test data must match the requirements of the chart type you have selected.

Verify the chart displays correctly.

Add a SQL Query macro outside the Chart macro body.

This is to ensure that the SQL Query macro is going to produce the correct format of the table.

Add your query to the SQL Query macro body.

For example:

select product as "Product", revenue as "Revenue" from revenue

Verify it produces the same table structure as the test table.

Now, you should have both macros configured correctly.

Combine the macros - this is the critical step!

Drag and drop the SQL macro into the body of the Chart macro (discard or save the test data somewhere else).

 

Product

Revenue

A

234,300

B

346,212

C

224,564