aboutsummaryrefslogtreecommitdiff
path: root/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/PercentFormatter.java
diff options
context:
space:
mode:
Diffstat (limited to 'MPChartLib/src/main/java/com/github/mikephil/charting/formatter/PercentFormatter.java')
-rw-r--r--MPChartLib/src/main/java/com/github/mikephil/charting/formatter/PercentFormatter.java51
1 files changed, 23 insertions, 28 deletions
diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/PercentFormatter.java b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/PercentFormatter.java
index 012fab77..de8a1025 100644
--- a/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/PercentFormatter.java
+++ b/MPChartLib/src/main/java/com/github/mikephil/charting/formatter/PercentFormatter.java
@@ -1,54 +1,49 @@
+
package com.github.mikephil.charting.formatter;
-import com.github.mikephil.charting.charts.PieChart;
-import com.github.mikephil.charting.data.PieEntry;
+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. (Recommended for PieChart)
+ * each value. (Recommeded for PieChart)
*
* @author Philipp Jahoda
*/
-public class PercentFormatter extends ValueFormatter
+public class PercentFormatter implements IValueFormatter, IAxisValueFormatter
{
- public DecimalFormat mFormat;
- private PieChart pieChart;
- private boolean percentSignSeparated;
+ protected DecimalFormat mFormat;
public PercentFormatter() {
mFormat = new DecimalFormat("###,###,##0.0");
- percentSignSeparated = true;
- }
-
- // Can be used to remove percent signs if the chart isn't in percent mode
- public PercentFormatter(PieChart pieChart) {
- this();
- this.pieChart = pieChart;
}
- // Can be used to remove percent signs if the chart isn't in percent mode
- public PercentFormatter(PieChart pieChart, boolean percentSignSeparated) {
- this(pieChart);
- this.percentSignSeparated = percentSignSeparated;
+ /**
+ * Allow a custom decimalformat
+ *
+ * @param format
+ */
+ public PercentFormatter(DecimalFormat format) {
+ this.mFormat = format;
}
+ // IValueFormatter
@Override
- public String getFormattedValue(float value) {
- return mFormat.format(value) + (percentSignSeparated ? " %" : "%");
+ public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
+ return mFormat.format(value) + " %";
}
+ // IAxisValueFormatter
@Override
- public String getPieLabel(float value, PieEntry pieEntry) {
- if (pieChart != null && pieChart.isUsePercentValuesEnabled()) {
- // Converted to percent
- return getFormattedValue(value);
- } else {
- // raw value, skip percent sign
- return mFormat.format(value);
- }
+ public String getFormattedValue(float value, AxisBase axis) {
+ return mFormat.format(value) + " %";
}
+ public int getDecimalDigits() {
+ return 1;
+ }
}