I am using MPAndroidChart BubbleChart v3.0.2. In this version I am unable to set my custom labels on xAxis. how can I set xAxis label for each bar. i.e (label1, label2 etc)
if any one worked in it or know how to do kindly share.
I am using MPAndroidChart BubbleChart v3.0.2. In this version I am unable to set my custom labels on xAxis. how can I set xAxis label for each bar. i.e (label1, label2 etc)
if any one worked in it or know how to do kindly share.
You can do this by extending IValueFormatter
. If you wanted to create a simple mapping of Entry
to String
labels you could do it like this:
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.utils.ViewPortHandler;
import java.util.Map;
public class MapValueFormatter implements IValueFormatter {
private final Map<Entry, String> labels;
public MapValueFormatter(Map<Entry, String> labels) {
this.labels = labels;
}
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
String label = labels.get(entry);
if (label == null) {
return "";
}
return label;
}
}
Then you can create labels like this:
Map<Entry,String> labels = new HashMap<>();
for (BubbleEntry bubbleEntry : dataSet.getValues()) {
labels.put(bubbleEntry, generateRandomString());
}
dataSet.setValueFormatter(new MapValueFormatter(labels));
The result looks like this:
I am sure you can do better though. Good luck!