Xc_折线图

···自定义的view

public class ZheView extends View {
private Paint mPaint;
private final static int textSize = 40;
private final static int startX = 100;
private final static int startY = 800;
private Path mPath;

public ZheView(Context context) {
    super(context);

}

public ZheView(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
}

public ZheView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    init();
}

private void init() {
    mPaint = new Paint();
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setColor(Color.RED);
    mPaint.setTextSize(textSize);
    mPath = new Path();
}

@Override
protected void onDraw(Canvas canvas) {
    canvas.drawPath(mPath,mPaint);
    canvas.drawLine(startX,startY,800,startY,mPaint);
    canvas.drawLine(startX,startY,startX,100,mPaint);

    canvas.drawText("0",100-mPaint.measureText("0")-20,800+textSize,mPaint);

    for (int i = 100; i < 600; i+=100) {
        String text = i+"";
        float textWidth = mPaint.measureText(text);
        canvas.drawText(text,startX+i-textWidth/2,startY+textSize,mPaint);//画x坐标
        canvas.drawText(text,startX-textWidth,startY-i+textSize,mPaint);//画y坐标

// canvas.drawLine(startX,200,300,400,mPaint);
// canvas.drawLine(startX,300,300,500,mPaint);
}
}
public void addPoi(int x,int y ){
mPath.lineTo(startX+x,startY-y);
invalidate();
}
}

···在界面显示的

int arrx[] = {100,140,200,260,300,400};
int arry[] = {30,100,300,210,500,310};
for(int i =0; i<6; i++){
zheView.addPoi(arrx[i],arrx[i]);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值