Skip to content

Commit

Permalink
Fix for empty bars
Browse files Browse the repository at this point in the history
  • Loading branch information
aint committed May 26, 2015
1 parent a4072c7 commit 4eda8cb
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,13 @@ public boolean onOptionsItemSelected(MenuItem item) {

@Override
public void onValueSelected(Entry e, int dataSetIndex, Highlight h) {
if (e == null) return;
if (e == null || ((BarEntry) e).getVals().length == 0) return;
BarEntry entry = (BarEntry) e;
int index = h.getStackIndex() == -1 ? 0 : h.getStackIndex();
String stackLabels = entry.getData().toString();
String label = mChart.getData().getXVals().get(entry.getXIndex()) + ", "
+ stackLabels.substring(1, stackLabels.length() - 1).split(",")[h.getStackIndex()];
double value = entry.getVals()[ h.getStackIndex() == -1 ? 0 : h.getStackIndex() ];
+ stackLabels.substring(1, stackLabels.length() - 1).split(",")[index];
double value = entry.getVals()[index];
double sum = mTotalPercentageMode ? mChart.getData().getDataSetByIndex(dataSetIndex).getYValueSum() : entry.getVal();
selectedValueTextView.setText(String.format(SELECTED_VALUE_PATTERN, label, value, value / sum * 100));
}
Expand Down

0 comments on commit 4eda8cb

Please sign in to comment.