PS: Invalid gradient is actually a BUG. It was not resolved until January 24, 2020. The current version 3.1.0 was packaged in 19, so you need to manually download the source code and import the project. I will not elaborate on importing the module.
Source address: https://github.com/PhilJay/MPAndroidChart
Use Fill:
import com.github.mikephil.charting.utils.Fill;
... ...
List<Fill> mGradientColors = new ArrayList<>();
... ...
BarDataSet mBarDataSet = new BarDataSet(mBarEntries, "");
mGradientColors.add(new Fill(new int[]{
Color.parseColor("#FFd9ef1f"), Color.parseColor("#FFDEF723"), Color.parseColor("#00e3ff28")}));
mGradientColors.add(new Fill(new int[]{
Color.parseColor("#FF0cb32f"), Color.parseColor("#FF1BD946"), Color.parseColor("#002bff5d")}));
mGradientColors.add(new Fill(new int[]{
Color.parseColor("#FFb30c14"), Color.parseColor("#FFD91B36"), Color.parseColor("#00ff2b58")}));
mBarDataSet.setFills(mGradientColors);
mBarChart.setData(new BarData(mBarDataSet));
mBarChart.invalidate();
Another BUG! ! !
- In order to have a gradient effect, two conditions need to be met:
1. Cannot getAxisLeft().setEnabled(false)
2. Must setAxisMinimum(0) - If you want to hide the shaft at the top, you can only:
YAxis yAxis_top = mBarChart.getAxisLeft(); yAxis_top.setAxisMinimum(0); yAxis_top.setDrawAxisLine(false); yAxis_top.setDrawGridLines(false); yAxis_top.setDrawLabels(false);