Interface ChartFunction

All Superinterfaces:
JsSnippet, Serializable

public interface ChartFunction extends JsSnippet
A JavaScript function of a chart option, such as a formatter, declared in a JsDefinition interface so that it is part of the frontend bundle. The browser runs the function from the bundle and does not compile any JavaScript from a string, so a chart that uses it works under a Content Security Policy without unsafe-eval.

Declare a method that returns this type, and get its implementation from JsSnippets.of(Class). The arguments of the method are available in the expression as $0, $1, and so on. Highcharts calls the function with the option's context as this. When the option passes arguments to the function, declare their names on the method with JsFunctionParameterNames.

 @JsDefinition
 public interface SalesFormatters extends JsSnippets {

     @JsExpression("return this.y / $0 + $1;")
     ChartFunction scaled(int divisor, String suffix);
 }

 SalesFormatters formatters = JsSnippets.of(SalesFormatters.class);
 dataLabels.setFormatterFunction(formatters.scaled(1000, "k"));
 
Since:
25.4