本文章部分参考
仿余额宝收益图实现 | 阿土's Blog
/** * 绘制折线 */ private void initLineChartView() { long now = new Date().getTime();// 当前时间 long t = 86400000; GraphViewSeries exampleSeries = new GraphViewSeries("", new GraphViewSeriesStyle(Color.rgb(0, 113, 185), DensityUtil .dip2px(MyDemoActivity.this, 3)),// 折线颜色(深蓝色) new GraphViewData[] { new GraphViewData(now - 6 * t, Double.parseDouble(str1)), new GraphViewData(now - 5 * t, Double.parseDouble(str2)), new GraphViewData(now - 4 * t, Double.parseDouble(str3)), new GraphViewData(now - 3 * t, Double.parseDouble(str4)), new GraphViewData(now - 2 * t, Double.parseDouble(str5)), new GraphViewData(now - 1 * t, Double.parseDouble(str6)), new GraphViewData(now, Double.parseDouble(str7)) }); GraphView graphView; graphView = new LineGraphView(MyDemoActivity.this, ""); ((LineGraphView) graphView).setDrawBackground(true); // ((LineGraphView) graphView) // .setBackgroundColor(Color.rgb(191, 230, 248));// 选择的背景颜色(淡蓝色) ((LineGraphView) graphView).setBackgroundColor(Color .parseColor("#200292D7"));// 选择的背景颜色(淡蓝色) ((LineGraphView) graphView).setDataPointsRadius(0); /** 字体色 */ int fontColor = Color.parseColor("#808080"); // 风格色//表格线颜色 graphView.getGraphViewStyle().setGridColor(Color.parseColor("#D8DDE3")); graphView.getGraphViewStyle().setHorizontalLabelsColor(fontColor); graphView.getGraphViewStyle().setVerticalLabelsColor(fontColor); // x轴标签数 graphView.getGraphViewStyle().setNumHorizontalLabels(7); // y轴标签数 graphView.getGraphViewStyle().setNumVerticalLabels(7); // // 隐藏y轴标签 graphView.setShowVerticalLabels(false); // 字号 yx轴 graphView.getGraphViewStyle().setTextSize( DensityUtil.dip2px(MyDemoActivity.this, 8)); // 图标利率数值字号 graphView.getGraphViewStyle().setTextSizeDot( DensityUtil.dip2px(MyDemoActivity.this, 15)); // 虚拟字体 为了空间大一点 // graphView.getGraphViewStyle().setTextSizeDots( // DensityUtil.dip2px(MyDemoActivity.this, 16)); graphView.getGraphViewStyle().setVerticalLabelsAlign(Align.RIGHT); graphView.getGraphViewStyle().setVerticalLabelsWidth( DensityUtil.dip2px(MyDemoActivity.this, 37));// 设置宽度(两列的宽度) graphView.addSeries(exampleSeries); final SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd", Locale.CHINESE); graphView.setCustomLabelFormatter(new CustomLabelFormatter() { @Override public String formatLabel(double value, boolean isValueX) { if (isValueX) { Date d = new Date((long) value); return dateFormat.format(d); } return null; } }); layoutChart.addView(graphView); }点击源代码