Android图表hellocharts(饼图PieChart)

xiaoxiao2021-02-28  51

public class PieChartFragment extends Fragment{  private View fragRootView;  private PieChartView pieChartView;  @Nullable  @Override  public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {  fragRootView=inflater.inflate(R.layout.fragment_pie_chart,null);  Log.i("out","ccc");  return fragRootView;  @Override  public void onActivityCreated(@Nullable Bundle savedInstanceState) {  pieChartView= (PieChartView) fragRootView.findViewById(R.id.pieChart);  initPieChart();  super.onActivityCreated(savedInstanceState);  private void initPieChart(){  //饼模块集合  List values=new ArrayList<>();   //添加饼模块(数值,模块颜色)   values.add(new SliceValue(60, Color.RED));   values.add(new SliceValue(90, Color.GRAY));   values.add(new SliceValue(33, Color.GREEN));   values.add(new SliceValue(99, Color.BLUE));   values.add(new SliceValue(120, Color.YELLOW)); PieChartData pieChartData=new PieChartData(values);   /*****************************饼中文字设置************************************/   //是否显示文本内容(默认为false)   pieChartData.setHasLabels(true);   //是否点击饼模块才显示文本(默认为false,为true时,setHasLabels(true)无效)   // pieChartData.setHasLabelsOnlyForSelected(true);   //文本内容是否显示在饼图外侧(默认为false)   pieChartData.setHasLabelsOutside(false);   //文本字体大小   pieChartData.setValueLabelTextSize(12);   //文本文字颜色   pieChartData.setValueLabelsTextColor(Color.WHITE);   //设置文本背景颜色   pieChartData.setValueLabelBackgroundColor(Color.RED);   //设置文本背景颜色时,必须设置自动背景为false   pieChartData.setValueLabelBackgroundAuto(false);   //设置是否有文字背景   pieChartData.setValueLabelBackgroundEnabled(false);   /*****************************中心圆设置************************************/   //饼图是空心圆环还是实心饼状(默认false,饼状)   pieChartData.setHasCenterCircle(true);   //中心圆的颜色(需setHasCenterCircle(true),因为只有圆环才能看到中心圆)   pieChartData.setCenterCircleColor(Color.WHITE);   //中心圆所占饼图比例(0-1)   pieChartData.setCenterCircleScale(0.4f);   /*=====================中心圆文本(可以只设置一个文本)==========/   /*--------------------第1个文本----------------------*/   //中心圆中文本   pieChartData.setCenterText1("第一个文本");   //中心圆的文本颜色   pieChartData.setCenterText1Color(Color.GRAY);   //中心圆的文本大小   pieChartData.setCenterText1FontSize(14);   /*--------------------第2个文本----------------------*/   //中心圆中文本   pieChartData.setCenterText2("第二个文本");   //中心圆的文本颜色   pieChartData.setCenterText2Color(Color.YELLOW);   //中心圆的文本大小   pieChartData.setCenterText2FontSize(16);   //饼图各模块的间隔(默认为0)   pieChartData.setSlicesSpacing(3);   pieChartView.setPieChartData(pieChartData);   //整个饼图所占视图比例(0-1)   pieChartView.setCircleFillRatio(0.7f);   //饼图是否可以转动(默认为true)   pieChartView.setChartRotationEnabled(true);   }   }

转载连接:https://www.aliyun.com/jiaocheng/52119.html
转载请注明原文地址: https://www.6miu.com/read-2623287.html

最新回复(0)