color布局文件
<color name="cash">#C0FF8C</color> <color name="wechat">#FFF78C</color> <color name="alipay">#FFD08B</color> <color name="bankcard">#8BEAFD</color> <color name="membershipcard">#FF8C9C</color> <color name="coupon">#D94E8A</color> <color name="discount">#FE9506</color>
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<SliceValue>(); /** * 总共的钱数 */ 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.youkuaiyun.com/chenzheng8975/article/details/78143604
设置点的大小及颜色:https://blog.youkuaiyun.com/qq_35563053/article/details/65628813
参考链接:https://blog.youkuaiyun.com/u010151514/article/details/52062052
https://blog.youkuaiyun.com/u012534831/article/details/51505683
注意:学习还是要动脑子的,不是拿来就能用的。