The user can achieve control of the whole dashboard through scripts, such as through scripts to achieve a timed refresh of the report. Scripts for dashboards can also be used to control individual components as a whole. Scripts for dashboards are divided into load-time scripts and change-time scripts. The execution conditions of these two types of scripts are different: load-time scripts run when the dashboard is opened, while change-time scripts run when there are changes in the components. 1. Script entry Select Dashboard > Advanced > Script in the right toolbar to open the Script dialog box. 2. Script dialog [On Load] is to run the contents of the script when a new dashboard is opened or when a dashboard is previewed. A run-on-load script executes only once when it first loads the dashboard. Ideal for one-off initialisation tasks such as defining dashboard parameters and variables. Variables declared in the run-on-load script have global scope and can be accessed by individual component scripts. To declare a local variable with the same name elsewhere, use the "var" keyword in the declaration to remove ambiguity. [On Change] This means that the content of the script is run when the component changes. The run-on-change processing is similar to the run-on-load processing, which is executed after the run-on-load script when the dashboard is loaded. However, unlike the load-time run script, the change-time run script is executed once each time the dashboard is refreshed. Scripts can be added from the change-time run to dynamically modify multiple elements. Variables declared in a run-on-change script will have global scope and can be accessed by individual component scripts. To declare a local variable with the same name elsewhere, use the "var" keyword in the declaration to remove ambiguity. 3. Example of dashboard level script For example, we have the following pivot component, named "Chart 1", which counts the total sales of different products and the percentage of sales at each market level. We want to use the rich text component to count the percentage of sales information, unified display in the dashboard, to get the effect of the figure below: •Implementation ideas 1)First get the total sales, the eastern market share value, the southern market share value, the western market share value, the central market share value. Script writing: var data=getViewData("pivot 1");//get data from pivot 1 var a=data.get(1,2);//get data from row 2, column 3 2)Assign the obtained values to the new parameters. Script writing: var b=data.get(2,6)*100; param['South Market']=left(b,5)+"%"//set the format of the data as a percentage and assign the data value to parameter South Market Referencing parameters in rich text. ➢For example: the parameter a, is directly quoted with ? {a} reference. •Specific steps 1)Click Dashboard > Advanced > Script in the right edit column, and select On Load. 2)Obtain the Eastern Percentage, Southern Percentage, Western Percentage, Central Percentage, and Sales data in thepivot by the cell where they are located. 3)Assign values to the parameters Eastern Percentage, Southern Percentage, Western Percentage, Central Percentage, and Sales. The code is as follows: 4)Create a new rich text component, click on the right side of the [Format > Edit], enter the text in the editing area to quote the parameters in front of the following figure: When you open the dashboard, the effect is as follows: 4. Other If you don't want to see the error message when you view the report, you can configure ignore.viewer.hint in the bi.properties file to control the popup window of the dashboard error report. When the value is true, viewing the dashboard will block the error message, and when the value is false, viewing the dashboard will pop up the error message normally. |