Android自定义饼图TTJPieChart

自定义View写的TTJPieChart

自定义ViewGroup写的TTJPieChartGroup

公司项目里抽出来的,希望对大家有用,也希望大家多多指教,接下来的时间我会补充讲解如何实现(代码中有很多注释)。

先给大家项目的GitHub链接:https://github.com/15915763299/TTJPieChart


TTJPieChart

改版淘淘金中使用的PieChart

目前 MyPieChartGroup 只支持三个变量的图表,MyPieChart 没有限制。 findView 之后务必要调用 init 方法初始化饼图

使用方法(举例):

xml:

 <...(包名).MyPieChartGroup
    android:id="@+id/my_pie_chart_group"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:background="#ffffff/>

 <...(包名).MyPieChart
    android:id="@+id/my_pie_chart"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:background="#ffffff/>

java:

  int[] colors = {
            R.color.freezing_amount,
            R.color.not_receive_principal,
            R.color.available_balance
  };
  float[] numbers = {5, 2, 90};
  String[] titles = {
           R.string.freezing_amount,
           R.string.unreceived_amount,
           R.string.avaliable_amount
  };
  // my_pie_chart_group
  MyPieChartGroup my_pie_chart_group = (MyPieChartGroup) findViewById(R.id.my_pie_chart_group);
  // 第一个参数为 titles 字体的大小,  单位:sp
  my_pie_chart_group.init(12, titles, colors, numbers);

  // my_pie_chart
  MyPieChart my_pie_chart = (MyPieChart) findViewById(R.id.my_pie_chart);
  //  第一个参数为饼图半径,  第二个参数为饼图圆弧宽度, 单位都为dip
  my_pie_chart.initChart(65, 25, colors, numbers);
  my_pie_chart.setStartPosition(180);

效果图:(橙色线条为测试的时候画上去的,代码中已注释掉)



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值