Reputation: 31
I've successfully used grouped barchart. I've got two bars per result (one red and one blue bar) but I haven't been able to retrieve X value when I click the blue one, only get the X value when I click the red bar. LINK TO IMAGE When I click either bar, the setOnChartValueSelectedListener method is called, but only when I click the red bar I get the XAxis value with this code:
barChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
@Override
public void onValueSelected(Entry e, Highlight h) {
if (null != barChart.getXAxis().getValueFormatter().getFormattedValue(e.getX(), barChart.getXAxis()) && !barChart.getXAxis().getValueFormatter().getFormattedValue(e.getX(), barChart.getXAxis()).isEmpty()) {
ContentManager.getInstance().setRegion(barChart.getXAxis().getValueFormatter().getFormattedValue(e.getX(), barChart.getXAxis()));
}
}
@Override
public void onNothingSelected() {
}
});
how can I get the value when I click the blue bar?
barChart.getXAxis().getValueFormatter().getFormattedValue(e.getX(), barChart.getXAxis())
that line returns the value clicking the red bar
Upvotes: 0
Views: 743
Reputation: 31
FIXED. Just use Math.floor to use a rounded value on a bar click.
Upvotes: 0