Create an xyLine Chart using the SQL macro - 11.x

Create an xyLine Chart using the SQL macro - 11.x

Scenario

Estimated Time: 11 min

As an example, let's create an xyLine chart to display "Books Printed vs. Sold" for the first 24 months in circulation. 

Background

Our scenario uses a data source profile, BookWarehouse, to query a rollup database table, CIRCULATION. The table contains aggregate metadata associated with the circulation of books which are rolled-up and reported on by year.

For this scenario, we focus on charting print vs. sold totals for the book "Nineteen Eighty-Four" in it's first year of circulation (1949):

SQL > SELECT * FROM circulation WHERE book_id =24 and year=1949; +---------+---------+----------+-----------+-----------+-----------+ |type | 6_months | 12_months | 18_months | 24_months | year | +---------+---------+----------+-----------+-----------+-----------+ |Printed | 8500.00 | 12000.00 | 20000.00 | 25000.00 | 1949 | |Sold | 9340.00 | 19000.00 | 14000.00 | 27000.00 | 1949 | +---------+---------+----------+-----------+-----------+-----------+

For more information about data source profiles, refer to Configure Data Source Profiles.

Our query against the CIRCULATION table looks like:

SELECT type as "Statistic Type" ,format(6_months,0) as "6" ,format(12_months,0) as "12" ,format(18_months,0) as "18" ,format(24_months,0) as "24" FROM circulation where year='1949' AND type='Printed' UNION SELECT type as "Statistic Type" ,format(6_months,0) as "6" ,format(12_months,0) as "12" ,format(18_months,0) as "18" ,format(24_months,0) as "24" FROM circulation where year='1949' AND type='Sold';

Steps

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

  1. Create a Confluence page

Create a Confluence page to create the macros needed to produce the chart.

  1. Create a page named Books in Circulation in a space accessible to the intended audience.

  2. Click Save to close the Page Restrictions screen.

  3. Click Save to save to publish the new page.


2. Configure the Chart macro

Edit the Books in Circulation page and perform 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.

    • Chart Title - title for the chart.

    • Chart Subtitle - subtitle for the chart.

    • Show legend - displays the name associated with the colored bars rendered.

  3. Click Save to save your changes to the macro's parameters.

Chart macro parameters:

Type

xyLine

Width (pixel value only)

600

Height (pixel value only)

400

Chart Title

Nineteen Eighty-Four

Chart Subtitle

Books Printed vs. Sold in 1949

Show legend


3. Configure the SQL Query macro

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

  1. Edit your Books in Circulation page.

  2. Add a line below your Chart macro.

  3. Using Markup, insert a new SQL macro on the page (more on Markup here).

  4. Adjust its parameters as shown on the right. The following parameters indicate:

    • 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 result set 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 result set of the SQL query.

  5. Click Save to save your changes to the SQL macro's parameters.

  6. With the cursor positioned inside the SQL macro container, paste in this SQL statement:

    SELECT type as "Statistic Type" ,format(6_months,0) as "6" ,format(12_months,0) as "12" ,format(18_months,0) as "18" ,format(24_months,0) as "24" FROM circulation where year='1949' AND type='Printed' UNION SELECT type as "Statistic Type" ,format(6_months,0) as "6" ,format(12_months,0) as "12" ,format(18_months,0) as "18" ,format(24_months,0) as "24" FROM circulation where year='1949' AND type='Sold';
  7. Using your mouse, "drag" the SQL macro container into your Chart macro container (see right).

SQL macro parameters:

10.x: SQL settings > SQL statement > Data source profile
8.x: Data source profile

BooksWarehouse

10.x: Display settings > Data layout > Use database column labels
8.x: Use database column labels

On

10.x: Display settings > Data layout > Show error if there are no rows
8.x: Show error if there are no rows

On

10.x: Display settings > Data layout > Text to display when there are no rows
8.x: Text to display when there are no rows

No rows selected

Moving the SQL macro inside the Chart macro:


  1. Save and test the page

Now, go back to the Books in Circulation page and click Save. You should now see a page that appears as shown on the right.

Books in Circulation:

Need support? Create a request with our support team.

Copyright © 2005 - 2025 Appfire | All rights reserved.