Scenario
Div | ||
---|---|---|
| ||
Estimated Time: 9 min |
In this scenario, we will create an XY Area chart to display "Publishing Revenue vs. Expense" by quarters in 2017.
Background
Our scenario will use a Data Source Profile called "BookWarehouse" to query a rollup database table called "PUBLICATION_RVE". The table contains aggregate rollup revenue and expense data by book, by quarter. For this scenario, we will focus on charting 2017 revenue and expense data for a single publisher:
Code Block | ||
---|---|---|
| ||
SQL > explain publication_rve;
+--------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+------------------+------+-----+---------+----------------+
| publisher_id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| type | varchar(255) | NO | | NULL | |
| Q1 | decimal(10,2) | NO | | NULL | |
| Q2 | decimal(10,2) | NO | | NULL | |
| Q3 | decimal(10,2) | NO | | NULL | |
| Q4 | decimal(10,2) | NO | | NULL | |
| year | varchar(255) | NO | | NULL | |
+--------------+------------------+------+-----+---------+----------------+ |
Our example query against the PUBLICATION_RVE table looks like:
Code Block | ||
---|---|---|
| ||
SELECT type as "Statement Type"
,format(Q1,0) as "Q1"
,format(Q2,0) as "Q2"
,format(Q2,0) as "Q3"
,format(Q2,0) as "Q4"
FROM publication_rve where year='2017'
AND type='Revenue'
UNION
SELECT type as "Statement Type"
,format(Q1,0) as "Q1"
,format(Q2,0) as "Q2"
,format(Q2,0) as "Q3"
,format(Q2,0) as "Q4"
FROM publication_rve where year='2017'
AND type='Expense'; |
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.
...
border | 0 |
---|---|
heading | 0 |
multiple | false |
enableHeadingAttributes | false |
columnAttributes | style="border:0;width=5%;",style="border:0;width=65%;",style="border:0;width=30%;max-width=30% !important;" |
id | steps_table |
enableSorting | false |
enableHighlighting | false |
...
Create a Confluence page
Create a Confluence page that will eventually contain the macros needed to produce the chart.
- Create a page named Publication Revenue vs. Expense in a space accessible to the desired audience.
- Click Save to close the Page Restrictions screen.
- Click Save to save to publish the new page.
...
...
Configure the Chart macro
Edit the Publication Revenue vs. Expense page and do the following:
- Insert the Chart macro.
- 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 xyLine chart.
- The Width parameter indicates the width of the chart in pixels.
- The Height parameter indicates the height of the chart in pixels.
- The Chart Title parameter provides a title for the chart.
- The Chart Subtitle parameter provides a subtitle for the chart.
- The Show legend parameter will display the name associated with the colored bars rendered.
- Click Save to save your changes to the Chart macro's parameters.
Chart macro parameters:
Type | pie |
Width (pixel value only) | 600 |
Height (pixel value only) | 400 |
Chart Title | Pearson |
Chart Subtitle | Revenue vs. Expense - 2017 |
Show legend |
...
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 | ||||||
---|---|---|---|---|---|---|
| ||||||
SELECT type as "Statement Type"
,format(Q1,0) as "Q1"
,format(Q2,0) as "Q2"
,format(Q2,0) as "Q3"
,format(Q2,0) as "Q4"
FROM publication_rve where year='2017'
AND type='Revenue'
UNION
SELECT type as "Statement Type"
,format(Q1,0) as "Q1"
,format(Q2,0) as "Q2"
,format(Q2,0) as "Q3"
,format(Q2,0) as "Q4"
FROM publication_rve where year='2017'
AND type='Expense';
|
Using your mouse, "drag" the SQL Macro container into your Chart Macro container (see right).
SQL Macro parameters:
Data source name | BooksWarehouse |
Use database column labels | selected |
Show error if there are no rows | selected |
Text to display when there are no rows | No rows selected |
Moving the SQL Macro inside the Chart Macro
...
Save and test the page
Now, go back to the Publication Revenue vs. Expense page and click Save to save it. You should now see a page that appears as shown on the right.
Final XY Area Chart:
...
Include Page | ||||
---|---|---|---|---|
|