Class PercentageCallback
- java.lang.Object
-
- org.pepstock.charba.client.impl.callbacks.PercentageCallback
-
- All Implemented Interfaces:
FormatterCallback
public final class PercentageCallback extends Object implements FormatterCallback
Formatter implementation for DataLabelsPlugin plugin in order to provide the percentage of the value.
Setting this object to formatter callback of DataLabelsPlugin options, it will return the percentage for each data index per dataset.- Author:
- Andrea "Stock" Stocchero
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_PRECISION
Default precision, 2.static String
NAN_AS_STRING
Default value ofDouble.NaN
as string, "NaN".
-
Constructor Summary
Constructors Constructor Description PercentageCallback()
Creates the formatter using the default values.PercentageCallback(boolean stacked)
Creates the formatter using the argument as flag to compute the percentage on stacked datasets.PercentageCallback(int precision)
Creates the formatter using the argument as number precision.PercentageCallback(int precision, boolean stacked)
Creates the formatter using the arguments as number format and as flag to compute the percentage on stacked datasets.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getPrecision()
Returns the number precision to apply.String
invoke(DataLabelsContext context, DataItem dataItem)
Returns the formatted label value.boolean
isStacked()
Returnstrue
if it computes the percentage on stacked datasets.
-
-
-
Field Detail
-
NAN_AS_STRING
public static final String NAN_AS_STRING
Default value ofDouble.NaN
as string, "NaN".- See Also:
- Constant Field Values
-
DEFAULT_PRECISION
public static final int DEFAULT_PRECISION
Default precision, 2.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PercentageCallback
public PercentageCallback()
Creates the formatter using the default values. The precision isDEFAULT_PRECISION
and stacked isfalse
.
-
PercentageCallback
public PercentageCallback(int precision)
Creates the formatter using the argument as number precision. The stacked isfalse
.- Parameters:
precision
- number precision to apply
-
PercentageCallback
public PercentageCallback(boolean stacked)
Creates the formatter using the argument as flag to compute the percentage on stacked datasets. The format isDEFAULT_PRECISION
.- Parameters:
stacked
- iftrue
computes the percentage on stacked datasets.
-
PercentageCallback
public PercentageCallback(int precision, boolean stacked)
Creates the formatter using the arguments as number format and as flag to compute the percentage on stacked datasets.- Parameters:
precision
- precision to applystacked
- iftrue
computes the percentage on stacked datasets.
-
-
Method Detail
-
getPrecision
public int getPrecision()
Returns the number precision to apply.- Returns:
- the number precision to apply
-
isStacked
public boolean isStacked()
Returnstrue
if it computes the percentage on stacked datasets.- Returns:
- if
true
computes the percentage on stacked datasets.
-
invoke
public String invoke(DataLabelsContext context, DataItem dataItem)
Description copied from interface:FormatterCallback
Returns the formatted label value.- Specified by:
invoke
in interfaceFormatterCallback
- Parameters:
context
-DataLabelsPlugin.ID
plugin context instancedataItem
- value container to be formatted.
Can be a simpledouble
,String
or aFloatingData
.- Returns:
- the label value to be showed
-
-