package com.github.mikephil.charting.formatter;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.utils.ViewPortHandler;
import java.text.DecimalFormat;
/**
* This IValueFormatter is just for convenience and simply puts a "%" sign after
* each value. (Recommeded for PieChart)
*
* @author Philipp Jahoda
*/
public class PercentFormatter implements IValueFormatter, IAxisValueFormatter
{
protected DecimalFormat mFormat;
public PercentFormatter() {
mFormat = new DecimalFormat("###,###,##0.0");
}
/**
* Allow a custom decimalformat
*
* @param format
*/
public PercentFormatter(DecimalFormat format) {
this.mFormat = format;
}
// IValueFormatter
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
return mFormat.format(value) + " %";
}
// IAxisValueFormatter
@Override
public String getFormattedValue(float value, AxisBase axis) {
return mFormat.format(value) + " %";
}
public int getDecimalDigits() {
return 1;
}
}