public class SalesReportLineCharUtil { // List<PointValue> mPointValues = new ArrayList<PointValue>(); // List<PointValue> mPointValuesWeiChat = new ArrayList<PointValue>(); // List<PointValue> mPointValuesAlipay = new ArrayList<PointValue>(); // List<PointValue> mPointValuesBank = new ArrayList<PointValue>(); // List<PointValue> mPointValuesVip = new ArrayList<PointValue>(); // List<PointValue> mPointValuesCoupon = new ArrayList<PointValue>(); // List<PointValue> mPointValuesDiscount = new ArrayList<PointValue>(); // List<PointValue> mPointValuesRefund = new ArrayList<PointValue>(); // List<AxisValue> mAxisXValues = new ArrayList<AxisValue>(); // // List<String> date = new ArrayList<>();//x轴 // List<Integer> score = new ArrayList<>();//数据点的集合 // List<Integer> weichatList = new ArrayList<>();//数据点的集合 // List<Integer> alipayList = new ArrayList<>();//数据点的集合 // List<Integer> bankList = new ArrayList<>();//数据点的集合 // List<Integer> vipList = new ArrayList<>();//数据点的集合 // List<Integer> couponList = new ArrayList<>();//数据点的集合 // List<Integer> discountList = new ArrayList<>();//数据点的集合 // List<Integer> refundList = new ArrayList<>();//数据点的集合 // // List<Line> lines = new ArrayList<Line>(); // LineChartData data = new LineChartData(); // // // Line line = new Line(mPointValues).setColor(MyApplication.getInstace().getResources().getColor(R.color.tabindicatorcolor)); //折线的颜色(现金)SetColor.parseColor("#FFCD41") // Line weichat = new Line(mPointValuesWeiChat).setColor(MyApplication.getInstace().getResources().getColor(R.color.green)); //折线的颜色 -- 微信 // Line alipay = new Line(mPointValuesAlipay).setColor(MyApplication.getInstace().getResources().getColor(R.color.report)); //折线的颜色 -- 支付宝 // Line bank = new Line(mPointValuesBank).setColor(MyApplication.getInstace().getResources().getColor(R.color.bank)); //折线的颜色 -- 银行卡 // Line vip = new Line(mPointValuesVip).setColor(MyApplication.getInstace().getResources().getColor(R.color.set_font_color)); //折线的颜色 -- 会员卡 // Line coupon = new Line(mPointValuesCoupon).setColor(MyApplication.getInstace().getResources().getColor(R.color.red_soil)); //折线的颜色 -- 优化券 // Line discount = new Line(mPointValuesDiscount).setColor(MyApplication.getInstace().getResources().getColor(R.color.orange)); //折线的颜色 -- 打折 // Line refund = new Line(mPointValuesRefund).setColor(MyApplication.getInstace().getResources().getColor(R.color.set_font_color)); //折线的颜色 -- 退款 public void initLineChart(Line line, Line weichat, Line alipay, Line bank, Line vip, Line coupon, Line discount, Line refund, LineChartData data, List<AxisValue> mAxisXValues, List<Line> lines, LineChartView lineChar) { refund.setPointRadius(1);//设置点的大小 refund.setHasLabels(true);//曲线的数据坐标是否加上备注 discount.setPointRadius(1);//设置点的大小 discount.setHasLabels(true);//曲线的数据坐标是否加上备注 coupon.setPointRadius(1);//设置点的大小 coupon.setHasLabels(true);//曲线的数据坐标是否加上备注 vip.setPointRadius(1);//设置点的大小 vip.setHasLabels(true);//曲线的数据坐标是否加上备注 bank.setPointRadius(1);//设置点的大小 bank.setHasLabels(true);//曲线的数据坐标是否加上备注 alipay.setPointRadius(1);//设置点的大小 alipay.setHasLabels(true);//曲线的数据坐标是否加上备注 weichat.setPointRadius(1);//设置点的大小 weichat.setHasLabels(true);//曲线的数据坐标是否加上备注 line.setShape(ValueShape.CIRCLE);//折线图上每个数据点的形状 这里是圆形 (有三种 :ValueShape.SQUARE ValueShape.CIRCLE ValueShape.DIAMOND) line.setPointRadius(1);//设置点的大小 line.setCubic(false);//曲线是否平滑,即是曲线还是折线 line.setFilled(false);//是否填充曲线的面积 line.setHasLabels(true);//曲线的数据坐标是否加上备注 // line.setHasLabelsOnlyForSelected(true);//点击数据坐标提示数据(设置了这个line.setHasLabels(true);就无效) line.setHasLines(true);//是否用线显示。如果为false 则没有曲线只有点显示 line.setHasPoints(true);//是否显示圆点 如果为false 则没有原点只有点显示(每个数据点都是个大的圆点) lines.add(line); lines.add(weichat); lines.add(alipay); lines.add(bank); lines.add(vip); lines.add(coupon); lines.add(discount); lines.add(refund); // LineChartData data = new LineChartData(); data.setLines(lines); data.setValueLabelsTextColor(MyApplication.getInstace().getResources().getColor(R.color.tabindicatorcolor));//设置数据颜色 data.setValueLabelBackgroundEnabled(false);//设置是否有数据背景 //坐标轴 Axis axisX = new Axis(); //X轴 axisX.setHasTiltedLabels(true); //X坐标轴字体是斜的显示还是直的,true是斜的显示 axisX.setTextColor(MyApplication.getInstace().getResources().getColor(R.color.light_black)); //设置字体颜色 axisX.setName(""); //表格名称(横坐标) axisX.setTextSize(10);//设置字体大小 axisX.setMaxLabelChars(8); //最多几个X轴坐标,意思就是你的缩放让X轴上数据的个数7<=x<=mAxisXValues.length axisX.setValues(mAxisXValues); //填充X轴的坐标名称 data.setAxisXBottom(axisX); //x 轴在底部 //data.setAxisXTop(axisX); //x 轴在顶部 axisX.setHasLines(true); //x 轴分割线 // Y轴是根据数据的大小自动设置Y轴上限(在下面我会给出固定Y轴数据个数的解决方案) Axis axisY = new Axis(); //Y轴 axisY.setName("");//y轴标注 axisY.setTextColor(MyApplication.getInstace().getResources().getColor(R.color.light_black));//y轴颜色 axisY.setTextSize(10);//设置字体大小 data.setAxisYLeft(axisY); //Y轴设置在左边 //data.setAxisYRight(axisY); //y轴设置在右边 //设置行为属性,支持缩放、滑动以及平移 lineChar.setInteractive(true); lineChar.setZoomType(ZoomType.HORIZONTAL); lineChar.setMaxZoom((float) 2);//最大方法比例 lineChar.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL); lineChar.setLineChartData(data);//刷新数据 lineChar.setVisibility(View.VISIBLE); /**注:下面的7,10只是代表一个数字去类比而已 * 当时是为了解决X轴固定数据个数。见(http://forum.xda-developers.com/tools/programming/library-hellocharts-charting-library-t2904456/page2); */ Viewport v = new Viewport(lineChar.getMaximumViewport()); v.left = 0; v.right = 7; lineChar.setCurrentViewport(v); } /** * 设置X 轴的显示 */ public void getAxisXLables(List<String> date, List<AxisValue> mAxisXValues) { for (int i = 0; i < date.size(); i++) { mAxisXValues.add(new AxisValue(i).setLabel(date.get(i))); } } /** * 图表的每个点的显示 */ public void getAxisPoints(List<Integer> score, List<PointValue> mPointValues) { for (int i = 0; i < score.size(); i++) { mPointValues.add(new PointValue(i, Float.parseFloat(score.get(i).toString()))); } } }
Android hellocharts折线图添加多条折线的工具类
猜你喜欢
转载自blog.csdn.net/yijiaodingqiankun/article/details/80986991
今日推荐
周排行