PS:漸變無效其實是BUG,直到2020年1月24号才解決,而目前的3.1.0版本是在19年打包的,是以需要手動下載下傳源碼并導入項目,導入module我就不闡述了
源碼位址:https://github.com/PhilJay/MPAndroidChart
使用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();
另一個BUG!!!
-
要想有漸變效果,還需要滿足2個條件:
1、不能 getAxisLeft().setEnabled(false)
2、必須 setAxisMinimum(0)
- 想要隐藏頂部的軸體隻能:
YAxis yAxis_top = mBarChart.getAxisLeft(); yAxis_top.setAxisMinimum(0); yAxis_top.setDrawAxisLine(false); yAxis_top.setDrawGridLines(false); yAxis_top.setDrawLabels(false);