Android统计图表_Android自定义柱形图Demo下载
程序员文章站
2021-12-12 11:39:42
...
记得之前也分享过一些关于统计图的Demo、之前分享都有很炫酷的效果、但是是通过SDK来做的、看不到里面的源代码、而今天分享的是一个继承至View的一个自定义View、大家可以通过这个Demo充分了解统计图的实现方式、以便于学习和改造自己的特定统计图
绘制统计图代码
public void drawChart(Canvas canvas) { if (flag == 1) { paint.setColor(Color.GREEN) ; int temp_screen = 30 ; for (int i = 0; i < 4; i ) { chart.setH(data_screen[i]) ; chart.setX(temp_screen 20 * 2 margin) ; chart.drawSelf(canvas, paint) ; margin = 20 ; temp_screen = chart.getX() ; } margin = 0 ; paint.setColor(Color.BLUE) ; int temp_power = 50 ; for (int i = 0; i < 4; i ) { chart.setH(data_power[i]) ; chart.setX(temp_power 20 * 2 margin) ; chart.drawSelf(canvas, paint) ; margin = 20 ; temp_power = chart.getX() ; } drawHighLines(canvas) ; } else if (flag == 2) { paint.setColor(Color.GREEN) ; int temp = 40 ; for (int i = 0; i < 4; i ) { chart.setH(data_total[i]) ; chart.setX(temp 20 * 2 margin) ; chart.drawSelf(canvas, paint) ; margin = 20 ; temp = chart.getX() ; } } }
绘制线条统计图
public void drawHighLines(Canvas canvas) { int[][] highPoints = new int[4][2] ; highPoints[0][0] = 90 ; highPoints[0][1] = data_total[0] ; highPoints[1][0] = 150 ; highPoints[1][1] = data_total[1] ; highPoints[2][0] = 210 ; highPoints[2][1] = data_total[2] ; highPoints[3][0] = 270 ; highPoints[3][1] = data_total[3] ; paint.setColor(Color.RED) ; for (int i = 0; i < 4; i ) { canvas.drawPoint(highPoints[i][0], 300 - highPoints[i][1], paint) ; canvas.drawText(data_total[i] "", highPoints[i][0] - 10, 300 - highPoints[i][1] - 10, paint) ; } float[] pts = new float[16] ; for (int i = 0; i < 12; i ) { pts[0] = 32 ; pts[1] = 300 - highPoints[0][1] ; pts[2] = highPoints[0][0] ; pts[3] = 300 - highPoints[0][1] ; pts[4] = highPoints[0][0] ; pts[5] = 300 - highPoints[0][1] ; pts[6] = highPoints[1][0] ; pts[7] = 300 - highPoints[1][1] ; pts[8] = highPoints[1][0] ; pts[9] = 300 - highPoints[1][1] ; pts[10] = highPoints[2][0] ; pts[11] = 300 - highPoints[2][1] ; pts[12] = highPoints[2][0] ; pts[13] = 300 - highPoints[2][1] ; pts[14] = highPoints[3][0] ; pts[15] = 300 - highPoints[3][1] ; } canvas.drawLines(pts, paint) ; }
android统计图表代码下载链接: android柱形图 密码: djjp
推荐阅读
-
Android编程实现仿优酷圆盘旋转菜单效果的方法详解【附demo源码下载】
-
Android开发之自定义view实现通讯录列表A~Z字母提示效果【附demo源码下载】
-
Android开发之HttpClient异步请求数据的方法详解【附demo源码下载】
-
Android开发实现的简单计算器功能【附完整demo源码下载】
-
Android编程调用系统自带的拍照功能并返回JPG文件示例【附demo源码下载】
-
Android基于TCP和URL协议的网络编程示例【附demo源码下载】
-
Android中使用自定义View实现下载进度的显示
-
Android编程实现的微信支付功能详解【附Demo源码下载】
-
Android异步下载图片并且缓存图片到本地DEMO详解
-
android 自定义圆角button效果的实例代码(自定义view Demo)