Versions Compared

Key

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

Scenario

Div
classtime

Image Removed Estimated Time: 13 min

In this scenario, we will create a Bar chart to display "Book Print Operational Costs". 

Background

Our scenario will use a Data Source Profile called "BookWarehouse" to query a database table called "PRINTOPERATION". The table contains current min, max, and average operational costs associated with the printing and go-to-market costs for books. For this scenario, we will focus on charting the current average market costs for each type of print operation:

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

Our example query against the PRINTOPERATION table looks like:

Code Block
languagesql
SELECT printoperation as "Service"
,format(avgcost,0) AS "Cost" 
FROM printoperation;

Steps

The following steps will 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 Confluence page

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

  1. Create a page named Print Operations 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 Print Operations 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 Type parameter indicates to display a Pie chart.
    • The Width parameter indicates the width of the chart in pixels.
    • The Height parameter indicates the height of the chart in pixels.
    • The Column parameter indicates the column name or order of mapping from the query result to the chart.
    • The Chart Title parameter provides a title for the chart.
    • The Show legend parameter will display the 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
ColumnService, Cost
Chart TitleAverage Print Operational Costs
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:

...

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

...

With the cursor positioned inside the SQL Macro container, paste in this SQL statement:

Code Block
languagesql
themeDJango
linenumberstrue
SELECT printoperation as "Service"
,format(avgcost,0) AS "Cost"
FROM printoperation;

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

SQL Macro parameters:

Data source nameBooksWarehouse
Use database column labelsselected
Show error if there are no rowsselected
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 Print Operations page and click Save to save it. You should now see a page that appears as shown on the right. 

Book Print Operational Costs:

...

Include Page
SUPPORT:Create a Pie chart using the SQL macro
SUPPORT:Create a Pie chart using the SQL macro