Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Scenario

Div
classtime

Image Removed Estimated Time: 11 min

In this scenario, we will create a 3-D bar chart to display "Top Publishers by Revenue (in $M). 

Background

Our scenario uses a data source profile called "BookWarehouse" to query a database table called "PUBLISHERS". The table contains the following columns and rows:

Code Block
languagesql
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 |
+----+------+-------------------+-----------------+---------+

Our example query against the PUBLISHERS table looks like:

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

Steps

The following steps demonstrate how to use Markup to insert Confluence's native Chart Macro and our SQL macro on a Confluence page.

...

border0
heading0
multiplefalse
enableHeadingAttributesfalse
columnAttributesstyle="border:0;width=5%;",style="border:0;width=65%;",style="border:0;width=30%;max-width=30% !important;"
idsteps_table
enableSortingfalse
enableHighlightingfalse

...

Create a Confluence page

Create a Confluence page that will eventually contain the macros needed to produce the chart.

  1. Create a page named Top Publishers Worldwide in a space accessible to the desired audience.
  2. Click Save to close the Page Restrictions screen.
  3. Click Save to save to publish the new page.

...

...

Configure the Chart macro

Edit the Top Publishers Worldwide page and do the following:

  1. Insert the Chart macro.
  2. Click the Chart macro container and click Edit so you can adjust its parameters as shown on the right. The following parameters indicate:
    • Type - type of a chart.
    • Width - width of the chart in pixels.
    • Height - height of the chart in pixels.
    • Display rendered data - a data table should be displayed after (below) the chart.
    • Chart Title - title for the chart.
    • Show in 3-D - add dimension to the bars within the chart.
    • Opacity - recommended when using 3-D and for bar the recommendation is 75%.
    • Horizontal-axis - column values rendered on the horizon line.
    • Vertical-axis - column values rendered on the vertical line.
    • Show legend - name associated with the colored bars rendered.
  3. Click Save to save your changes to the Chart macro's parameters.

Chart macro parameters:

Typepie
Width (pixel value only)600
Height (pixel value only)400
Chart TitleTop Publishers by Revenue
Show in 3-D(tick)
Opacity75
Horizontal-axis labelPublisher
Vertical-axis labelRevenue (in $M)
Show legend(tick)

...

Configure the SQL Query macro

This step uses the SQL macro, to retrieve the data that will be displayed in the bar chart. To configure the SQL  macro, do the following:

...

  • Data source profile - name of the data source profile that you set up.
  • Use database column labels - 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.
  • Show error if there are no rows - displays an error if no rows are returned in the resultset of the SQL query.
  • Text to display when there are no rows - text of the error message to be displayed when no rows are returned in the resultset of the SQL query.

...

Paste the SQL statement in SQL settings > SQL statement > SQL statement:

Code Block
languagesql
themeDJango
linenumberstrue
SELECT company_name as "Publisher"
,CONCAT('$',format(revenue,0)) as "M Rev" 
FROM publishers 
ORDER BY rank asc;

Using your mouse, drag the SQL macro container into your Chart macro container (see right).

SQL macro parameters:

SQL settings > SQL statement > Data source profileBooksWarehouse
Display settings > Data layout > Use database column labelsOn
Display settings > Data layout > Show error if there are no rowsOn
Display settings > Data layout > Text to display when there are no rowsNo rows selected

Moving the SQL macro inside the Chart Macro

Image Removed

...

Save and test the page

Now, go back to the Top Publishers Worldwide page and click Save to save it. You should now see a page that appears as shown on the right. 

...

Top Publishers by Revenue (in $M):

Image Removed

Image Removed

Include Page
SUPPORT:Create a Bar chart using SQL macro
SUPPORT:Create a Bar chart using SQL macro