自定义坐标系图.doc_第1页
自定义坐标系图.doc_第2页
自定义坐标系图.doc_第3页
自定义坐标系图.doc_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

mw_shl_code=java,truepackage com.example.sql;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.Path;import android.graphics.PointF;import android.util.AttributeSet;import android.view.View;public class Coordinates extends View private Paint mPaint;/ 标题private boolean mTitle;private String Title;private int TitleHeight;private PointF TitlePoint;/ 边距private int PL, PR, PB, PT;/ 横轴纵轴长度。private float XPix, YPix;private float XScale, YScale;private int XLen, YLen;/ 横轴纵轴标识和单位private String XPrickle, YPrickle;private String XName = X, YName = Y;/ 参考坐标private PointF Point1 = new PointF();private PointF mPointBaseValue = new PointF();/ 交叉点坐标中心点private PointF Pointp = new PointF();public Coordinates(Context context) super(context, null);init();public Coordinates(Context context, AttributeSet attrs) super(context, attrs);init();private void init() mPaint = new Paint();mPaint.setColor(Color.BLACK);/ 设置边距setCoordinatesPadding(0, 0, 0, 0);/ 设置标题setTitleHeight(20);setTitleName(标题);mTitle = true;TitlePoint = new PointF(PL, TitleHeight);public void setTitleHeight(int height) TitleHeight = height;/ 设置图表标题public void setTitleName(String titleName) Title = titleName;/ 设置边距public void setCoordinatesPadding(int leftPad, int rightPad, int topPad,int bottomPad) PL = leftPad + 40;PR = rightPad + 40;PT = topPad + 10;PB = bottomPad + 40;/ 设置坐标名称和单位public void setAxisNamePrickleXY(String xName, String xPrickle,String yName, String yPrickle) XName = xName;XPrickle = xPrickle;YName = yName;YPrickle = yPrickle;/ 中心坐标和坐标轴圆心所在的点。public void onSizeChanged(int w, int h, int oldw, int oldh) XLen = w - PL - PR;YLen = h - PB - PT - (mTitle ? TitleHeight : 0);Pointp.set(PL, h - PB);Point1.set(XLen / 2 + Pointp.x, Pointp.y - YLen / 2);super.onSizeChanged(w, h, oldw, oldh);public void onDraw(Canvas canvas) super.onDraw(canvas);if (canvas = null) return;canvas.drawColor(Color.WHITE);/ 画标题canvas.drawText(Title, TitlePoint.x, TitlePoint.y, mPaint);/ X轴上标签canvas.drawText(80, 138, 350, mPaint);canvas.drawText(85, 188, 350, mPaint);canvas.drawText(90, 258, 350, mPaint);canvas.drawText(100, 308, 350, mPaint);canvas.drawText(110, 358, 350, mPaint);/ canvas.drawText(, 238, 350, mPaint);/ Y轴上标签canvas.drawText(120, 8, 290, mPaint);canvas.drawText(130, 8, 240, mPaint);canvas.drawText(140, 8, 190, mPaint);canvas.drawText(160, 8, 140, mPaint);canvas.drawText(180, 8, 90, mPaint);/ canvas.drawText(, 8, 160, mPaint);/ 柱状图标签canvas.drawText(Normal BP, 40, 285, mPaint);canvas.drawText(High-normal BP, 40, 235, mPaint);canvas.drawText(Mild Hypertension, 40, 185, mPaint);canvas.drawText(Moderate Hypertension, 40, 135, mPaint);canvas.drawText(Severe Hypertension, 40, 85, mPaint);/ 画X轴canvas.drawLine(Pointp.x, Pointp.y, Pointp.x + XLen, Pointp.y, mPaint);/ 画Y轴canvas.drawLine(Pointp.x, Pointp.y, Pointp.x, Pointp.y - YLen, mPaint);/ 画X轴箭头float x = Pointp.x + XLen, y = Pointp.y;drawjiantou(canvas, new PointF(x, y), new PointF(x - 10, y - 5),new PointF(x - 10, y + 5);canvas.drawText(XName, x - 15, y + 18, mPaint);canvas.drawText(( + XPrickle + ), x - 15, y + 18 + 12, mPaint);Paint paint = new Paint();/ 画Y轴箭头x = Pointp.x;y = Pointp.y - YLen;drawjiantou(canvas, new PointF(x, y), new PointF(x - 5, y + 10),new PointF(x + 5, y + 10);canvas.drawText(YName + ( + YPrickle + ), x + 12, y + 15, mPaint);/ 填充一paint.setStyle(Paint.Style.FILL);paint.setColor(Color.BLUE);canvas.drawRect(41, 285, 240, 335, paint);/ canvas.drawRect:canvas.drawRect(left, top, right, bottom, paint)/ left:是矩形距离左边的X轴,top:是矩形距离上边的Y轴,right:是矩形距离右边的X轴,/ bottom:是矩形距离下边的Y轴/ 填充二paint.setStyle(Paint.Style.FILL);paint.setColor(Color.RED);canvas.drawRect(41, 285, 180, 235, paint);/ 填充三paint.setStyle(Paint.Style.FILL);paint.setColor(Color.YELLOW);canvas.drawRect(41, 235, 160, 185, paint);/ 填充四paint.setStyle(Paint.Style.FILL);paint.setColor(Color.GREEN);canvas.drawRect(41, 185, 140, 135, paint);/ 用于画坐标轴的箭头,三角形private void drawjiantou(Canvas canvas, PointF p1, PointF p2, PointF p3) Path path = new Path();path

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论