Skip to content

Commit 66d80a0

Browse files
committed
Fixed issue concerning all equal values (issue PhilJay#409).
1 parent 64f6ab0 commit 66d80a0

5 files changed

Lines changed: 22 additions & 11 deletions

File tree

‎MPChartExample/AndroidManifest.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.xxmassdeveloper.mpchartexample"
4-
android:versionCode="37"
4+
android:versionCode="38"
55
android:versionName="2.0.8" >
66

77
<uses-sdk

‎MPChartExample/build.gradle‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ android {
66
defaultConfig {
77
minSdkVersion 16
88
targetSdkVersion 21
9-
versionCode 37
9+
versionCode 38
1010
versionName '2.0.8'
1111

1212
sourceSets {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,14 @@ protected void onCreate(Bundle savedInstanceState) {
9999
leftAxis.setLabelCount(8);
100100
leftAxis.setValueFormatter(custom);
101101
leftAxis.setPosition(YAxisLabelPosition.OUTSIDE_CHART);
102+
leftAxis.setSpaceTop(15f);
102103

103104
YAxis rightAxis = mChart.getAxisRight();
104105
rightAxis.setDrawGridLines(false);
105106
rightAxis.setTypeface(mTf);
106107
rightAxis.setLabelCount(8);
107108
rightAxis.setValueFormatter(custom);
109+
rightAxis.setSpaceTop(15f);
108110

109111
Legend l = mChart.getLegend();
110112
l.setPosition(LegendPosition.BELOW_CHART_LEFT);

‎MPChartLib/src/com/github/mikephil/charting/charts/BarLineChartBase.java‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,13 @@ protected void calcMinMax() {
311311

312312
float leftRange = Math.abs(maxLeft - (mAxisLeft.isStartAtZeroEnabled() ? 0 : minLeft));
313313
float rightRange = Math.abs(maxRight - (mAxisRight.isStartAtZeroEnabled() ? 0 : minRight));
314+
315+
// in case all values are equal
316+
if (leftRange == 0f)
317+
maxLeft = maxLeft + 1f;
318+
319+
if (rightRange == 0f)
320+
maxRight = maxRight + 1f;
314321

315322
float topSpaceLeft = leftRange / 100f * mAxisLeft.getSpaceTop();
316323
float topSpaceRight = rightRange / 100f * mAxisRight.getSpaceTop();
@@ -356,7 +363,7 @@ protected void calculateOffsets() {
356363
offsetRight += mLegend.mTextWidthMax + mLegend.getXOffset() * 2f;
357364

358365
} else if (mLegend.getPosition() == LegendPosition.LEFT_OF_CHART
359-
|| mLegend.getPosition() == LegendPosition.LEFT_OF_CHART_CENTER) {
366+
|| mLegend.getPosition() == LegendPosition.LEFT_OF_CHART_CENTER) {
360367

361368
offsetLeft += mLegend.mTextWidthMax + mLegend.getXOffset() * 2f;
362369

@@ -370,11 +377,13 @@ protected void calculateOffsets() {
370377

371378
// offsets for y-labels
372379
if (mAxisLeft.needsOffset()) {
373-
offsetLeft += mAxisLeft.getRequiredWidthSpace(mAxisRendererLeft.getPaintAxisLabels());
380+
offsetLeft += mAxisLeft.getRequiredWidthSpace(mAxisRendererLeft
381+
.getPaintAxisLabels());
374382
}
375383

376384
if (mAxisRight.needsOffset()) {
377-
offsetRight += mAxisRight.getRequiredWidthSpace(mAxisRendererRight.getPaintAxisLabels());
385+
offsetRight += mAxisRight.getRequiredWidthSpace(mAxisRendererRight
386+
.getPaintAxisLabels());
378387
}
379388

380389
float xlabelheight = mXAxis.mLabelHeight * 2f;

‎MPChartLib/src/com/github/mikephil/charting/renderer/YAxisRenderer.java‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ public void computeAxis(float yMin, float yMax) {
6060
yMax = (float) p1.y;
6161
} else {
6262

63-
if (!mYAxis.isStartAtZeroEnabled())
63+
if (!mYAxis.isStartAtZeroEnabled()) {
6464
yMin = (float) Math.min(p1.y, p2.y);
65-
else
65+
} else
6666
yMin = 0;
6767
yMax = (float) Math.max(p1.y, p2.y);
6868
}
@@ -275,19 +275,19 @@ public void renderLimitLines(Canvas c) {
275275

276276
float[] pts = new float[4];
277277
Path limitLinePath = new Path();
278-
278+
279279
for (int i = 0; i < limitLines.size(); i++) {
280280

281281
LimitLine l = limitLines.get(i);
282-
282+
283283
pts[1] = l.getLimit();
284284
pts[3] = l.getLimit();
285285

286286
mTrans.pointValuesToPixel(pts);
287287

288288
pts[0] = mViewPortHandler.contentLeft();
289289
pts[2] = mViewPortHandler.contentRight();
290-
290+
291291
limitLinePath.moveTo(pts[0], pts[1]);
292292
limitLinePath.lineTo(pts[2], pts[3]);
293293

@@ -297,7 +297,7 @@ public void renderLimitLines(Canvas c) {
297297

298298
c.drawPath(limitLinePath, mLimitLinePaint);
299299
limitLinePath.reset();
300-
// c.drawLines(pts, mLimitLinePaint);
300+
// c.drawLines(pts, mLimitLinePaint);
301301

302302
String label = l.getLabel();
303303

0 commit comments

Comments
 (0)