ANS-0461 · SUITESCRIPT DEVELOPMENT

How to Format Numbers with Google Charts in NetSuite for Enhanced Visualization?

Learn to apply custom number formatting, including negative color styling, to data columns within Google Charts for clearer data representation.

Short answer

To format numbers in Google Charts, instantiate the google.visualization.NumberFormat object with desired options like negativeColor and negativeParens. Then, apply this formatter to specific data columns using formatter.format(data, columnNumber). Ensure allowHTML is set to true when drawing the chart for proper styling.

Scenario

Users often require specific number formatting within Google Charts to improve data readability, especially when dealing with negative values. The default chart rendering may not provide the desired visual cues, such as distinct coloring or parenthesizing for negative numbers, leading to less intuitive data interpretation.

Solution

To apply custom number formatting, such as styling negative values, within Google Charts, utilize the google.visualization.NumberFormat object. First, create an instance of the formatter, specifying the desired formatting options:

var formatter  new google.visualization.NumberFormat({
    negativeColor: 'red',
    negativeParens: true
});

Once the formatter is created, it must be applied individually to the relevant data columns.

formatter.format(data, columnNumber);

Important Note: For the negative color option to be correctly rendered, the allowHTML option must be set to true when the chart is drawn.

Expert NetSuite Support

Need help with this NetSuite issue?

SuiteScript Development consulting and configuration support

Talk to a consultant