Overview
Application Scenario
In some cases, you need to set specific indicators for the category axis in the chart to keep track of the work progress. The following figure shows the effect.
Implementation Method
You can use the API function FR.remoteEvaluate(Formula) and the built-in report function VALUE(TableData,TargetCol,OrgCol,Element) to customize the format of X axis labels.
Example
Data Preparation
1. Create a general report and create a built-in dataset named ds1, as shown in the following figure.
2. Create a built-in dataset named ds2, where the percents field represents the proportion of each salesperson's sales to the total sales, as shown in the following figure.
Chart Insertion
Merge required cells and insert a column chart, as shown in the following figure.
Data Binding
Bind the data to the column chart to display the sales of each product for each salesperson, as shown in the following figure.
Custom Axis Label
Choose Style > Axis > X Axis and select Custom for Axis Label Format. After entering the JavaScript code, you need to select Use HTML to Parse Text Content, as shown in the following figure.
The JavaScript codes are as follows.
function() {
//The VALUE function returns the percentage data after calculation.
var a=(FR.remoteEvaluate("value('ds2',2,1,'" + this+ "')")*100).toFixed(1);
//The category name and percent are displayed together as the axis label, and the axis labels for Amy and Mike are marked in red.
if(this=='Amy'||this=='Mike'){
return "<font color='red'>"+this+":"+a+"%"+"</font>" }else{
return this+": "+a+"%";
}
}
Effect Display
PC
Save the template and click Pagination Preview, as shown in the following figure.
Mobile Terminal
The template can be previewed on both the DataAnalyst app and the HTML5 terminal. The following figure shows the effect.
Template Download
For details, you can download the template: Value Indicator on the Category Axis.cpt.
Notes
During the template preview, you may find that the window "This call poses security risks. If you need to call it, modify Forbid Script to Call Formula in Security Mangament." pops up and NaN% is displayed in data, as shown in the following figure.
In this case, you need to log in to the decision-making system, choose System Management > Security Management> Security, and disable Forbide Script to Call Formula, as shown in the following figure.