Android(安卓)折线图之hellocharts (饼状图)饼图
16lz
2021-01-25
color布局文件
java代码中需要设置的参数
<color name="cash">#C0FF8Ccolor><color name="wechat">#FFF78Ccolor><color name="alipay">#FFD08Bcolor><color name="bankcard">#8BEAFDcolor><color name="membershipcard">#FF8C9Ccolor><color name="coupon">#D94E8Acolor><color name="discount">#FE9506color>string布局文件
<string name="CashText">现金string><string name="WeChatText">微信string><string name="AliPayText">支付宝string><string name="BankcardText">银行卡string><string name="MembershipText">会员卡string><string name="CouponsText">优惠券string><string name="DiscountText">打折string>有颜色提示的饼图布局
<LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:orientation="horizontal"> <LinearLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight="1" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:orientation="horizontal"> <ImageView android:layout_width="20dp" android:layout_height="8dp" android:background="@color/cash" /> <TextView android:id="@+id/textView6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/CashText" android:textSize="12sp" /> LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:orientation="horizontal"> <ImageView android:layout_width="20dp" android:layout_height="8dp" android:background="@color/wechat" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/WeChatText" android:textSize="12sp" /> LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:orientation="horizontal"> <ImageView android:layout_width="20dp" android:layout_height="8dp" android:background="@color/alipay" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/AliPayText" android:textSize="12sp" /> LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:orientation="horizontal"> <ImageView android:layout_width="20dp" android:layout_height="8dp" android:background="@color/bankcard" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/BankcardText" android:textSize="12sp" /> LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:orientation="horizontal"> <ImageView android:layout_width="20dp" android:layout_height="8dp" android:background="@color/membershipcard" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/MembershipText" android:textSize="12sp" /> LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:orientation="horizontal"> <ImageView android:layout_width="20dp" android:layout_height="8dp" android:background="@color/coupon" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/CouponsText" android:textSize="12sp" /> LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:orientation="horizontal"> <ImageView android:layout_width="20dp" android:layout_height="8dp" android:background="@color/discount" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/DiscountText" android:textSize="12sp" /> LinearLayout> LinearLayout> <lecho.lib.hellocharts.view.PieChartView android:id="@+id/sr_pcv" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="4" />LinearLayout>饼图:控件属性自己设置
<lecho.lib.hellocharts.view.PieChartView android:id="@+id/sr_pcv" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="@color/reddish" />
java代码中需要设置的参数
private void initPicChar() {//初始化饼图 pieList = new ArrayList给折线图的数据设置背景及颜色:https://blog.csdn.net/chenzheng8975/article/details/78143604 设置点的大小及颜色:https://blog.csdn.net/qq_35563053/article/details/65628813 参考链接:https://blog.csdn.net/u010151514/article/details/52062052(); /** * 总共的钱数 */ Float money_count = Float.parseFloat(trade_money) + parseFloat(trade_weichat_money) + parseFloat(trade_alipay_money) + parseFloat(trade_bank_money) + parseFloat(trade_vip_money) + parseFloat(trade_coupon_money) + parseFloat(discount); SliceValue sliceValue = null; for (int i = 0; i < listPays.size(); i++) { if (listPays.get(i).getName().equals("现金")) { float xianjin = Float.parseFloat(trade_money) / money_count * 100; //创建一个新的值 sliceValue = new SliceValue(); //设置每个扇形区域的值,float型 sliceValue.setValue(xianjin); //设置每个扇形区域的颜色 sliceValue.setColor(Color.GREEN); //设置每个扇形区域的Lable,不设置的话,默认显示数值// sliceValue.setLabel(listPays.get(i).getPrice()+"现金"); }else if (listPays.get(i).getName().equals("微信")) { float weixin = Float.parseFloat(trade_weichat_money) / money_count * 100; //创建一个新的值 sliceValue = new SliceValue(); //设置每个扇形区域的值,float型 sliceValue.setValue(weixin); //设置每个扇形区域的颜色 sliceValue.setColor(Color.YELLOW); //设置每个扇形区域的Lable,不设置的话,默认显示数值// sliceValue.setLabel("现金"); }else if (listPays.get(i).getName().equals("支付宝")) { float zhifubao = Float.parseFloat(trade_alipay_money) / money_count * 100; //创建一个新的值 sliceValue = new SliceValue(); //设置每个扇形区域的值,float型 sliceValue.setValue(zhifubao); //设置每个扇形区域的颜色 sliceValue.setColor(Color.BLUE); //设置每个扇形区域的Lable,不设置的话,默认显示数值// sliceValue.setLabel("现金"); }else if (listPays.get(i).getName().equals("银行卡")) { float yinhangka = Float.parseFloat(trade_bank_money) / money_count * 100; //创建一个新的值 sliceValue = new SliceValue(); //设置每个扇形区域的值,float型 sliceValue.setValue(yinhangka); //设置每个扇形区域的颜色 sliceValue.setColor(Color.BLUE); //设置每个扇形区域的Lable,不设置的话,默认显示数值// sliceValue.setLabel("现金"); }else if (listPays.get(i).getName().equals("会员卡")) { float huiyuanka = Float.parseFloat(trade_vip_money) / money_count * 100; //创建一个新的值 sliceValue = new SliceValue(); //设置每个扇形区域的值,float型 sliceValue.setValue(huiyuanka); //设置每个扇形区域的颜色 sliceValue.setColor(Color.BLACK); //设置每个扇形区域的Lable,不设置的话,默认显示数值// sliceValue.setLabel("现金"); }else if (listPays.get(i).getName().equals("优惠券")) { float youhuiquan = Float.parseFloat(trade_coupon_money) / money_count * 100; //创建一个新的值 sliceValue = new SliceValue(); //设置每个扇形区域的值,float型 sliceValue.setValue(youhuiquan); //设置每个扇形区域的颜色 sliceValue.setColor(Color.GREEN); //设置每个扇形区域的Lable,不设置的话,默认显示数值// sliceValue.setLabel("现金"); }else if (listPays.get(i).getName().equals("打折")) { float dazhe = Float.parseFloat(discount) / money_count * 100; //创建一个新的值 sliceValue = new SliceValue(); //设置每个扇形区域的值,float型 sliceValue.setValue(dazhe); //设置每个扇形区域的颜色 sliceValue.setColor(Color.RED); //设置每个扇形区域的Lable,不设置的话,默认显示数值// sliceValue.setLabel("现金"); } pieList.add(sliceValue); } PieChartData data = new PieChartData(pieList); data.setHasLabels(true); data.setHasLabelsOnlyForSelected(false); data.setHasLabelsOutside(true); srPcv.setPieChartData(data);//设置饼图数据// srPcv.callTouchListener();// srPcv.setChartRotation();// srPcv.isChartRotationEnabled(); }
https://blog.csdn.net/u012534831/article/details/51505683
注意:学习还是要动脑子的,不是拿来就能用的。
更多相关文章
- Android中shape详解
- Android修改状态栏颜色全方位教程
- Android点击空白区域,隐藏输入法软键盘
- Android(安卓)常用颜色 html 代码
- PopupWindow 展开后点击返回键无效?
- achartengine之折线图---简单用法
- Android代码实现状态选择器
- Android调用OpenCV2.4.10实现二维码区域定位
- Android(安卓)onTouch 点击事件执行两次分析