Skip to content

Commit 5a15715

Browse files
committed
New formatters for YAxis and XAxis with greater customizeability.
1 parent 94dae2e commit 5a15715

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+355
-202
lines changed

MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivity.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
import com.github.mikephil.charting.data.filter.Approximator.ApproximatorType;
3434
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
3535
import com.github.mikephil.charting.highlight.Highlight;
36-
import com.github.mikephil.charting.utils.ValueFormatter;
37-
import com.xxmassdeveloper.mpchartexample.custom.MyValueFormatter;
36+
import com.github.mikephil.charting.formatter.YAxisValueFormatter;
37+
import com.xxmassdeveloper.mpchartexample.custom.MyYAxisValueFormatter;
3838
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
3939

4040
import java.util.ArrayList;
@@ -92,7 +92,7 @@ protected void onCreate(Bundle savedInstanceState) {
9292
xAxis.setDrawGridLines(false);
9393
xAxis.setSpaceBetweenLabels(2);
9494

95-
ValueFormatter custom = new MyValueFormatter();
95+
YAxisValueFormatter custom = new MyYAxisValueFormatter();
9696

9797
YAxis leftAxis = mChart.getAxisLeft();
9898
leftAxis.setTypeface(mTf);
@@ -267,7 +267,6 @@ private void setData(int count, float range) {
267267
dataSets.add(set1);
268268

269269
BarData data = new BarData(xVals, dataSets);
270-
// data.setValueFormatter(new MyValueFormatter());
271270
data.setValueTextSize(10f);
272271
data.setValueTypeface(mTf);
273272

MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivityMultiDataset.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import com.github.mikephil.charting.data.Entry;
2525
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
2626
import com.github.mikephil.charting.highlight.Highlight;
27-
import com.github.mikephil.charting.utils.LargeValueFormatter;
27+
import com.github.mikephil.charting.formatter.LargeValueFormatter;
2828
import com.xxmassdeveloper.mpchartexample.custom.MyMarkerView;
2929
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
3030

MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ protected void onCreate(Bundle savedInstanceState) {
103103
llXAxis.setTextSize(10f);
104104

105105
XAxis xAxis = mChart.getXAxis();
106-
//xAxis.setXValueFormatter(new MyCustomXValueFormatter());
106+
//xAxis.setValueFormatter(new MyCustomXAxisValueFormatter());
107107
//xAxis.addLimitLine(llXAxis); // add x-axis limit line
108108

109109
LimitLine ll1 = new LimitLine(130f, "Upper Limit");
@@ -133,8 +133,8 @@ protected void onCreate(Bundle savedInstanceState) {
133133

134134
mChart.getAxisRight().setEnabled(false);
135135

136-
mChart.getViewPortHandler().setMaximumScaleY(2f);
137-
mChart.getViewPortHandler().setMaximumScaleX(2f);
136+
//mChart.getViewPortHandler().setMaximumScaleY(2f);
137+
//mChart.getViewPortHandler().setMaximumScaleX(2f);
138138

139139
// add data
140140
setData(45, 100);

MPChartExample/src/com/xxmassdeveloper/mpchartexample/PieChartActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
2424
import com.github.mikephil.charting.utils.ColorTemplate;
2525
import com.github.mikephil.charting.highlight.Highlight;
26-
import com.github.mikephil.charting.utils.PercentFormatter;
26+
import com.github.mikephil.charting.formatter.PercentFormatter;
2727
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
2828

2929
import java.util.ArrayList;

MPChartExample/src/com/xxmassdeveloper/mpchartexample/StackedBarActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
3030
import com.github.mikephil.charting.utils.ColorTemplate;
3131
import com.xxmassdeveloper.mpchartexample.custom.MyValueFormatter;
32+
import com.xxmassdeveloper.mpchartexample.custom.MyYAxisValueFormatter;
3233
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
3334

3435
public class StackedBarActivity extends DemoBase implements OnSeekBarChangeListener, OnChartValueSelectedListener {
@@ -71,7 +72,7 @@ protected void onCreate(Bundle savedInstanceState) {
7172

7273
// change the position of the y-labels
7374
YAxis yLabels = mChart.getAxisLeft();
74-
yLabels.setValueFormatter(new MyValueFormatter());
75+
yLabels.setValueFormatter(new MyYAxisValueFormatter());
7576
mChart.getAxisRight().setEnabled(false);
7677

7778
XAxis xLabels = mChart.getXAxis();

MPChartExample/src/com/xxmassdeveloper/mpchartexample/StackedBarActivityNegative.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
import com.github.mikephil.charting.data.filter.Approximator.ApproximatorType;
2525
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
2626
import com.github.mikephil.charting.highlight.Highlight;
27-
import com.github.mikephil.charting.utils.ValueFormatter;
27+
import com.github.mikephil.charting.formatter.ValueFormatter;
28+
import com.github.mikephil.charting.utils.ViewPortHandler;
29+
import com.github.mikephil.charting.formatter.YAxisValueFormatter;
2830
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
2931

3032
import java.text.DecimalFormat;
@@ -211,16 +213,23 @@ public void onNothingSelected() {
211213

212214
}
213215

214-
private class CustomFormatter implements ValueFormatter {
216+
private class CustomFormatter implements ValueFormatter, YAxisValueFormatter {
215217

216218
private DecimalFormat mFormat;
217219

218220
public CustomFormatter() {
219221
mFormat = new DecimalFormat("###");
220222
}
221223

224+
// data
222225
@Override
223-
public String getFormattedValue(float value) {
226+
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
227+
return mFormat.format(Math.abs(value)) + "m";
228+
}
229+
230+
// YAxis
231+
@Override
232+
public String getFormattedValue(float value, YAxis yAxis) {
224233
return mFormat.format(Math.abs(value)) + "m";
225234
}
226235
}

MPChartExample/src/com/xxmassdeveloper/mpchartexample/custom/MyCustomXValueFormatter.java renamed to MPChartExample/src/com/xxmassdeveloper/mpchartexample/custom/MyCustomXAxisValueFormatter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package com.xxmassdeveloper.mpchartexample.custom;
22

33
import com.github.mikephil.charting.utils.ViewPortHandler;
4-
import com.github.mikephil.charting.utils.XValueFormatter;
4+
import com.github.mikephil.charting.formatter.XAxisValueFormatter;
55

66
/**
77
* Created by Philipp Jahoda on 14/09/15.
88
*/
9-
public class MyCustomXValueFormatter implements XValueFormatter {
9+
public class MyCustomXAxisValueFormatter implements XAxisValueFormatter {
1010

11-
public MyCustomXValueFormatter() {
11+
public MyCustomXAxisValueFormatter() {
1212
// maybe do something here or provide parameters in constructor
1313
}
1414

MPChartExample/src/com/xxmassdeveloper/mpchartexample/custom/MyFillFormatter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.github.mikephil.charting.data.LineDataSet;
44
import com.github.mikephil.charting.interfaces.LineDataProvider;
5-
import com.github.mikephil.charting.utils.FillFormatter;
5+
import com.github.mikephil.charting.formatter.FillFormatter;
66

77
/**
88
* Created by Philipp Jahoda on 12/09/15.
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.xxmassdeveloper.mpchartexample.custom;
22

3-
import com.github.mikephil.charting.utils.ValueFormatter;
3+
import com.github.mikephil.charting.data.Entry;
4+
import com.github.mikephil.charting.formatter.ValueFormatter;
5+
import com.github.mikephil.charting.utils.ViewPortHandler;
46

57
import java.text.DecimalFormat;
68

@@ -11,10 +13,9 @@ public class MyValueFormatter implements ValueFormatter {
1113
public MyValueFormatter() {
1214
mFormat = new DecimalFormat("###,###,###,##0.0");
1315
}
14-
16+
1517
@Override
16-
public String getFormattedValue(float value) {
18+
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
1719
return mFormat.format(value) + " $";
1820
}
19-
2021
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.xxmassdeveloper.mpchartexample.custom;
2+
3+
import com.github.mikephil.charting.components.YAxis;
4+
import com.github.mikephil.charting.formatter.YAxisValueFormatter;
5+
6+
import java.text.DecimalFormat;
7+
8+
public class MyYAxisValueFormatter implements YAxisValueFormatter {
9+
10+
private DecimalFormat mFormat;
11+
12+
public MyYAxisValueFormatter() {
13+
mFormat = new DecimalFormat("###,###,###,##0.0");
14+
}
15+
16+
@Override
17+
public String getFormattedValue(float value, YAxis yAxis) {
18+
return mFormat.format(value) + " $";
19+
}
20+
}

0 commit comments

Comments
 (0)