MPAndroidChart use can also read my previous articles
1. The transverse bar graph binary
2. Gradient binary histogram MPAndroidChart
Direct Figure:
Specifically how to use MPAndroidChart can already see the code
Directly on the code:
initialization
pieChart.setNoDataText("暂无数据");
pieChart.setUsePercentValues(true);
pieChart.getDescription().setEnabled(false);
pieChart.setDragDecelerationFrictionCoef(0.95f);
pieChart.setExtraOffsets(5, 10, 5, 5);
// pieChart.setExtraBottomOffset(10);
// pieChart.setExtraOffsets(0, 0, 0, 0);
// holder.pieChart.setCenterText("ABC");
pieChart.setDrawEntryLabels(false);
pieChart.setDrawHoleEnabled(true);
pieChart.setHoleColor(Color.WHITE);
pieChart.setDrawCenterText(false);//饼状图中间可以添加文字
pieChart.setHoleRadius(80f);
pieChart.setTransparentCircleRadius(0f);
pieChart.setRotationAngle(0);
pieChart.animateY(1400, Easing.EaseInOutQuad);
Legend l = pieChart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
if(type==1) {
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
}else{
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
}
l.setOrientation(Legend.LegendOrientation.VERTICAL);
l.setDrawInside(false);
l.setXEntrySpace(5f);
l.setYEntrySpace(0f);
l.setYOffset(10f);
// entry label styling
pieChart.setEntryLabelColor(Color.WHITE);
// holder.pieChart.setEntryLabelTypeface(tfRegular);
pieChart.setEntryLabelTextSize(12f);
Binding data
ArrayList<PieEntry> entries = new ArrayList<>();
PieDataSet dataSet = new PieDataSet(entries, "");
dataSet.setSliceSpace(3f);
ArrayList<Integer> colors = new ArrayList<>();
for (int i = 0; i < values.size(); i++) {
entries.add(new PieEntry((float)values.get(i),datas.get(i)));
colors.add(resources.getColor(Constants.COLORS_ARRAY[i]));
}
dataSet.setColors(colors);
dataSet.setValueTextColor(Color.TRANSPARENT);
PieData pieData = new PieData(dataSet);
pieData.setValueFormatter(new PercentFormatter(new DecimalFormat()));
pieChart.setData(pieData);
pieChart.notifyDataSetChanged();
pieChart.invalidate();
About MPAndroidChart use before I can see several articles about lateral double value histogram
If you can help look for easy viewing, welcome to discuss concerns
1. The transverse bar graph binary