Class Percentage


  • public final class Percentage
    extends Object
    Utility to calculate the percentage of the value based on the datasets of chart.
    Author:
    Andrea "Stock" Stocchero
    • Method Detail

      • compute

        public static double compute​(IsChart chart,
                                     double value,
                                     AbstractDatasetContext context)
        Computes the percentage of the value based on the data of datasets. If the dataset is composed by DataPoint, it uses the AbstractXYDataPoint.getY() value to compute the percentage. The stack is ignored.
        Parameters:
        chart - chart instance
        value - current value to be evaluated
        context - data labels plugin context
        Returns:
        the percentage value, a double between 0 and 1. If the datasets does not contains any data, it will return Double.NaN.
      • compute

        public static double compute​(IsChart chart,
                                     double value,
                                     AbstractDatasetContext context,
                                     boolean stacked)
        Computes the percentage of the value based on the data of datasets. If the dataset is composed by DataPoint, it uses the AbstractXYDataPoint.getY() value to compute the percentage.
        Parameters:
        chart - chart instance
        value - current value to be evaluated
        context - data labels plugin context
        stacked - if true, it calculates the total at the same data index (cross datasets), otherwise if false it calculates the total at the same dataset index (single dataset)
        Returns:
        the percentage value, a double between 0 and 1. If the datasets does not contains any data, it will return Double.NaN.