PieChart使用
主要详细说明饼状图的使用。关联库什么的就不用说了。
- PieChart
- Legend
PieChart
- Entry
Entry(float val, int xIndex) :某个xIndex的数值val; PieData
可以自己构造JSON数据进行填充。
PieData(List xVals, PieDataSet dataSet):需要的xVals是分类名称;PieDataSet
PieDataSet(List yVals, String label) :一个Entry相当于饼状图的一个小部分;
展示PieChart
- 属性列表
pieChart.setHoleColorTransparent(true);
pieChart.setTransparentCircleRadius(EcityConstants.ZERO);
pieChart.setHoleRadius(EcityConstants.ZERO);
pieChart.setDescription(description);
pieChart.setNoDataTextDescription(EcityConstants.NO_DATA_DESCRIPTION);
pieChart.setDrawCenterText(false);
pieChart.setDrawSliceText(false);
pieChart.setDrawHoleEnabled(true);
pieChart.setRotationAngle(EcityConstants.ROTATION_ANGLE);
pieChart.setRotationEnabled(true);
pieChart.setUsePercentValues(true);
pieData.setValueFormatter(new PercentFormatter());
pieData.setValueTextSize(11f);
pieData.setValueTextColor(Color.WHITE);
pieChart.setData(pieData);
pieChart.animateXY(EcityConstants.ANIMATE_X, EcityConstants.ANIMATE_Y);
Legend
可自定义,或者从chartView获取到Legend图例。
不涉及到大量数据分类,可以直接使用内置的图例。
- 属性列表
Legend legend = pieChart.getLegend();
legend.setEnabled(true);//自定义时,需要设置为false
legend.setPosition(Legend.LegendPosition.RIGHT_OF_CHART_CENTER);
legend.setTextColor(colors[1]);
legend.setTextSize(10);
legend.setXEntrySpace(8f);
legend.setYEntrySpace(8f);
end.
by.ShawnAtom