Skip to content

Commit 8d65596

Browse files
committed
Default spaceMin/spaceMax for bar charts
This avoids having to set custom axisMinimum/axisMaximum, or offsetting x
1 parent b77063d commit 8d65596

3 files changed

Lines changed: 9 additions & 11 deletions

File tree

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,12 @@ private void setData(int count, float range) {
231231

232232
float start = 0f;
233233

234-
mChart.getXAxis().setAxisMinimum(start);
235-
mChart.getXAxis().setAxisMaximum(start + count + 2);
236-
237234
ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
238235

239236
for (int i = (int) start; i < start + count + 1; i++) {
240237
float mult = (range + 1);
241238
float val = (float) (Math.random() * mult);
242-
yVals1.add(new BarEntry(i + 1f, val));
239+
yVals1.add(new BarEntry(i, val));
243240
}
244241

245242
BarDataSet set1;

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ protected void onCreate(Bundle savedInstanceState) {
6161
xAxis.setDrawAxisLine(false);
6262
xAxis.setTextColor(Color.LTGRAY);
6363
xAxis.setTextSize(13f);
64-
xAxis.setAxisMinimum(0f);
65-
xAxis.setAxisMaximum(5f);
6664
xAxis.setLabelCount(5);
6765
xAxis.setCenterAxisLabels(true);
6866
xAxis.setGranularity(1f);
@@ -81,11 +79,11 @@ protected void onCreate(Bundle savedInstanceState) {
8179

8280
// THIS IS THE ORIGINAL DATA YOU WANT TO PLOT
8381
final List<Data> data = new ArrayList<>();
84-
data.add(new Data(0.5f, -224.1f, "12-29"));
85-
data.add(new Data(1.5f, 238.5f, "12-30"));
86-
data.add(new Data(2.5f, 1280.1f, "12-31"));
87-
data.add(new Data(3.5f, -442.3f, "01-01"));
88-
data.add(new Data(4.5f, -2280.1f, "01-02"));
82+
data.add(new Data(0f, -224.1f, "12-29"));
83+
data.add(new Data(1f, 238.5f, "12-30"));
84+
data.add(new Data(2f, 1280.1f, "12-31"));
85+
data.add(new Data(3f, -442.3f, "01-01"));
86+
data.add(new Data(4f, -2280.1f, "01-02"));
8987

9088
xAxis.setValueFormatter(new IAxisValueFormatter() {
9189
@Override

MPChartLib/src/main/java/com/github/mikephil/charting/charts/BarChart.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ protected void init() {
5757
mRenderer = new BarChartRenderer(this, mAnimator, mViewPortHandler);
5858

5959
setHighlighter(new BarHighlighter(this));
60+
61+
getXAxis().setSpaceMin(0.5f);
62+
getXAxis().setSpaceMax(0.5f);
6063
}
6164

6265
@Override

0 commit comments

Comments
 (0)