Custom Javascript Field Display Format

Follow these steps to continue configuring a field at the dataset level using Javascript (js). See Changing the Field Display Format for initial navigation steps.

Availability Note. This feature is limited to users who have both the Manage custom styles and Manage dataset privileges.
  1. In the Edit Field Parameters window modal, under the Display Format tab, select Custom Javascript from the Category menu.

  2. Under Custom JS Format Function, enter the following js code:

    function myFunc(value) {            
      // Show the number in trillions with a dollar sign return
      '$${value/1000000000000}';
      }
    entering js format
  3. Click Apply.

  4. Save the changes to the dataset.

    In this case, under Dataset: World Life Expectancy, click Save.

  5. To verify that the format applies to all new visuals that use the field, repeat the steps in Testing the Calculated Field.

    Let's compare the visuals before and after we apply the js format on the gdp field.

    • Before we apply the js format, the visual displays the currency with many trailing zeros.
    • After applying the custom js format, notice that the trailing zeros no longer appear.
    js-configured field display