You can override the BarDataSet class to achieve this
public class MyBarDataSet extends BarDataSet {
public MyBarDataSet(List<BarEntry> yVals, String label) {
super(yVals, label);
}
@Override
public int getColor(int index) {
if(getEntryForXIndex(index).getVal() < 95) // less than 95 green
return mColors.get(0);
else if(getEntryForXIndex(index).getVal() < 100) // less than 100 orange
return mColors.get(1);
else // greater or equal than 100 red
return mColors.get(2);
}
}
And you need to define your colors like this:
MyBarDataSet set = new MyBarDataSet(yVals, "");
set.setColors(new int[]{ContextCompat.getColor(context, R.color.green),
ContextCompat.getColor(context, R.color.orange),
ContextCompat.getColor(context, R.color.red)});
ArrayList<BarDataSet> dataSets = new ArrayList<>();
dataSets.add(set);
BarData data = new BarData(xVals, dataSets);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…