Hello,
These functionalities are already prebuilt on version 5.0 onwars using formatting options.
However if you are using version 4.1 or lower, this document will help you to do that. Here we are providing custom JavaScript code, you can use this further to customize all your numeric data formatting requirements for cross tabular view. Below is the code and explanation of how to use this code:
CODE:
hi_container.set("postFetch",function(c){
var viz_Options = c.get("viz_Options");
var responseData = c.get("responseData");
console.log(responseData);
var temp = responseData.data;
temp.map(item =>{
var tempp = d3.format(',.' +"2f")(item.sum_travel_cost);
tempp = '$ ' + tempp;
tempp = tempp + ' %' ;
item.sum_travel_cost = tempp;
})
console.log(responseData , 'new');
c.set("viz_Options",viz_Options);
});
Explanation:
Here in the above code we are using post fetch method to format the data.
var tempp = d3.format(’,.’ +“2f”)(item.sum_travel_cost);
Here ‘sum_travel_cost’ is the column name on which you want to apply formatting. You can change the name of column with which you want to apply formatting.
d3.format(’,.’ +“2f”)
This snippet will add thousand separator and numbers of digits after decimal to values of above mentioned column.
- Change 2 to number of digits after decimal you want.
- If you only want thousand separator then the code will be:
d3.format(’,’)
tempp = '$ ’ + tempp;
With this line we are adding ‘$’ as a prefix to the values. (you can change to the prefix you want to add).
tempp = tempp + ‘ %’ ;
With this line we are adding ‘%’ as a suffix to the values. (you can change to the suffix you want to add)
item.sum_travel_cost = tempp;
Here also change the column on which you want to apply formatting.
Usage:
Copy the above code and make necessary changes to the code to fulfill your requirement.
After that click on EDITOR option and in that go to JS Editor and paste the code snippet.
After pasting code click on Inject button. Now the formatting is applied to crosstab. You can see that in the below image with sum_travel_cost $ as prefix and % as suffix got applied.
Thank You,
Helical Insight.