Skip to content

Commit a78e227

Browse files
danielgindiqiduhe
authored andcommitted
Make min/max axis labels configurable
ChartsOrg/Charts#2894
1 parent 40a80e8 commit a78e227

File tree

1 file changed

+37
-4
lines changed
  • MPChartLib/src/main/java/com/github/mikephil/charting/components

1 file changed

+37
-4
lines changed

MPChartLib/src/main/java/com/github/mikephil/charting/components/AxisBase.java

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,39 @@ public abstract class AxisBase extends ComponentBase {
151151
*/
152152
public float mAxisRange = 0f;
153153

154+
private int mAxisMinLabels = 2;
155+
private int mAxisMaxLabels = 25;
156+
157+
/**
158+
* The minumum number of labels on the axis
159+
*/
160+
public int getAxisMinLabels() {
161+
return mAxisMinLabels;
162+
}
163+
164+
/**
165+
* The minumum number of labels on the axis
166+
*/
167+
public void setAxisMinLabels(int labels) {
168+
if (labels > 0)
169+
mAxisMinLabels = labels;
170+
}
171+
172+
/**
173+
* The maximum number of labels on the axis
174+
*/
175+
public int getAxisMaxLabels() {
176+
return mAxisMaxLabels;
177+
}
178+
179+
/**
180+
* The maximum number of labels on the axis
181+
*/
182+
public void setAxisMaxLabels(int labels) {
183+
if (labels > 0)
184+
mAxisMaxLabels = labels;
185+
}
186+
154187
/**
155188
* default constructor
156189
*/
@@ -314,10 +347,10 @@ public boolean isDrawLabelsEnabled() {
314347
*/
315348
public void setLabelCount(int count) {
316349

317-
if (count > 25)
318-
count = 25;
319-
if (count < 2)
320-
count = 2;
350+
if (count > getAxisMaxLabels())
351+
count = getAxisMaxLabels();
352+
if (count < getAxisMinLabels())
353+
count = getAxisMinLabels();
321354

322355
mLabelCount = count;
323356
mForceLabels = false;

0 commit comments

Comments
 (0)