Chart Titles
Adding Dataset Values to Chart Titles
I struggled with this but finally figured it out.
I was trying to tie a dataset column field to a report chart title. (Basically, it was fiscal year that needed updating every year when the report ran.) The challenge I had was how to populate the global variable with data from the dataset that was bound to the chart. If someone knows a better way please let me know.
These are the steps I took:
Insert a chart in a table that is bound to your dataset. In my case I inserted the chart in the footer to make sure the table had pulled the data first. Hide all the rows that you don't want showing.
Select onCreate in the first script dropdown.
Create a global variable and set it with your data field as follows:
reportContextSetPersistentGlobalVariable("yourvariablename", this.getValue())
Select the Chart and then select the SCRIPT tab. Retrieve the variable and use it in the chart title
function beforeGeneration( chart, icsc){ var fyear = icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("fy"); var chartTitle = "Monthly Running Total on Expenses for FY" + fyear"; //Write out chart title chart.getTitle().getLabel().getCaption().setValue(chartTitle); }

Update - 8/9/21 - I found out that this is grabbing the last data element from the table. Will have to figure out how to get the data out of the grouping in the table.
Modifying a chart title with the current date
Script onRenderfunction beforeGeneration( chart, context ){ var d = new Date(); // Gets the current date and time var myDate = (d.getMonth() + 1) + "/" + d.getDate() + "/" + (d.getYear()+ 1900) // Breaks down the date in short date formate mm/dd/yyyy var title = "Aging Phases for BMO as of " + myDate;//Create the variable for the chart title text chart.getTitle().getLabel().getCaption().setValue(title); //script for adding the title to the chart.
To extract a year from a date for text you can do the following also:
var titleYear = new Date(paramStart.getTime()).getFullYear();
This script is for accessing and using the parameter value.
- Select the chart.
- Select the Script tab
- Choose OnRender on the left dropdown
- Choose beforeGeneration on the right dropdown
function beforeGeneration( chart, icsc ) var paramShop = icsc.getExternalContext().getScriptable().getParameterValue("Shop"); var title = "Monthly Overtime for "; chart.getTitle().getLabel().getCaption().setValue(title + paramShop);
Using the begin and end date parameters in a chart title
function beforeGeneration( chart, icsc ) var paramBegin = icsc.getExternalContext().getScriptable().getParameterValue("StartDate"); var paramEnd = icsc.getExternalContext().getScriptable().getParameterValue("EndDate"); var startDate =(paramBegin.getMonth() + 1) + "/" + paramBegin.getDate() + "/" + (paramBegin.getYear()+ 1900); var endDate =(paramEnd.getMonth() + 1) + "/" + paramEnd.getDate() + "/" + (paramEnd.getYear()+ 1900); var title = "This is my chart title from "; //This is the text for you chart title chart.getTitle().getLabel().getCaption().setValue(title + startDate + " to " + endDate);
Comments
Post a Comment