Skip to content

Commit 75be29e

Browse files
committed
Added markerview support for HorizontalBarChart (PhilJay#1010) - still bugfixing needed.
1 parent 9ecce15 commit 75be29e

5 files changed

Lines changed: 34 additions & 9 deletions

File tree

MPChartExample/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
22

33
android {
44
compileSdkVersion 23
5-
buildToolsVersion '23.0.0'
5+
buildToolsVersion '23.0.1'
66
defaultConfig {
77
minSdkVersion 8
88
targetSdkVersion 23

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
3232
import com.github.mikephil.charting.highlight.Highlight;
3333
import com.github.mikephil.charting.utils.ColorTemplate;
34+
import com.xxmassdeveloper.mpchartexample.custom.MyMarkerView;
3435
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
3536

3637
import java.util.ArrayList;
@@ -105,6 +106,11 @@ protected void onCreate(Bundle savedInstanceState) {
105106
yr.setDrawGridLines(false);
106107
// yr.setInverted(true);
107108

109+
MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
110+
111+
// set the marker to the chart
112+
mChart.setMarkerView(mv);
113+
108114
setData(12, 50);
109115
mChart.animateY(2500);
110116

MPChartLib/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apply plugin: 'android-maven'
33

44
android {
55
compileSdkVersion 23
6-
buildToolsVersion '23.0.0'
6+
buildToolsVersion '23.0.1'
77
// resourcePrefix 'mpcht'
88
defaultConfig {
99
minSdkVersion 8

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

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -548,15 +548,34 @@ protected float[] getMarkerPosition(Entry e, Highlight highlight) {
548548

549549
BarData bd = (BarData) mData;
550550
float space = bd.getGroupSpace();
551+
int setCount = mData.getDataSetCount();
552+
int i = e.getXIndex();
551553

552-
float x = e.getXIndex() * (mData.getDataSetCount() - 1) + dataSetIndex + space * e.getXIndex() + space
553-
/ 2f;
554+
if(this instanceof HorizontalBarChart) {
554555

555-
xPos += x;
556+
// calculate the x-position, depending on datasetcount
557+
float y = i + i * (setCount - 1) + dataSetIndex + space * i + space / 2f ;
556558

557-
BarEntry entry = (BarEntry) e;
558-
if(entry.getVals() != null) {
559-
yPos = highlight.getRange().to;
559+
yPos = y;
560+
561+
BarEntry entry = (BarEntry) e;
562+
if(entry.getVals() != null) {
563+
xPos = highlight.getRange().to;
564+
} else {
565+
xPos = e.getVal();
566+
}
567+
} else {
568+
569+
float x = i + i * (setCount - 1) + dataSetIndex + space * i + space / 2f;
570+
571+
xPos = x;
572+
573+
BarEntry entry = (BarEntry) e;
574+
if(entry.getVals() != null) {
575+
yPos = highlight.getRange().to;
576+
} else {
577+
yPos = e.getVal();
578+
}
560579
}
561580
}
562581

MPChartLib/src/com/github/mikephil/charting/utils/Transformer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public float[] generateTransformedValuesHorizontalBarChart(List<? extends Entry>
262262
int i = e.getXIndex();
263263

264264
// calculate the x-position, depending on datasetcount
265-
float x = e.getXIndex() + i * (setCount - 1) + dataSet + space * i
265+
float x = i + i * (setCount - 1) + dataSet + space * i
266266
+ space / 2f ;
267267
float y = e.getVal();
268268

0 commit comments

Comments
 (0)