折线图

折线图

//新建一个画笔
Paint paint = new Paint();
//文字大小
paint.setTextSize(40);
//文字颜色
paint.setColor(Color.WHITE);
//画一条线
 canvas.drawLine(100, 900, 650, 900, paint);
//画一个圆点
 canvas.drawCircle(200, 750, 10, paint);
 //写文字
 canvas.drawText("文字", 600, 950, paint);

代码

package com.bawei.lmx.zhoukao3_427.clinear;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

public class ClinearLayout extends View {

    private Paint paintxy;
    private Paint paint;
    private Paint paintY1, paintY2, paintY3, paintY4, paintY5;
    private Paint paintText;


    public ClinearLayout(Context context) {
        super(context, null);
    }

    public ClinearLayout(Context context, AttributeSet attrs) {
        super(context, attrs);

    }

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

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //文字
        paintText = new Paint();
        paintText.setTextSize(40);
        paintText.setColor(Color.WHITE);
        canvas.drawText("电商项目第三周周考", 200, 60, paintText);
        //X
        paintxy = new Paint();
        paintxy.setStrokeWidth(5);
        paintxy.setColor(Color.WHITE);
        canvas.drawLine(100, 900, 650, 900, paintxy);
        //Y
        paintY1 = new Paint();
        paintY1.setStrokeWidth(5);
        paintY1.setColor(Color.BLUE);
        canvas.drawLine(100, 900, 100, 740, paintY1);
        paintY2 = new Paint();
        paintY2.setStrokeWidth(5);
        paintY2.setColor(Color.GREEN);
        canvas.drawLine(100, 740, 100, 580, paintY2);
        paintY3 = new Paint();
        paintY3.setStrokeWidth(5);
        paintY3.setColor(Color.YELLOW);
        canvas.drawLine(100, 580, 100, 420, paintY3);
        paintY4 = new Paint();
        paintY4.setStrokeWidth(5);
        paintY4.setColor(Color.RED);
        canvas.drawLine(100, 420, 100, 260, paintY4);
        paintY5 = new Paint();
        paintY5.setStrokeWidth(5);
        paintY5.setColor(Color.GRAY);
        canvas.drawLine(100, 260, 100, 100, paintY5);
        //线
        this.paint = new Paint();
        this.paint.setStrokeWidth(5);
        this.paint.setColor(Color.WHITE);
        canvas.drawLine(100, 900, 200, 750, paint);
        canvas.drawLine(200, 750, 300, 500, paint);
        canvas.drawLine(300, 500, 400, 650, paint);
        canvas.drawLine(400, 650, 500, 800, paint);
        canvas.drawLine(500, 800, 600, 450, paint);


        Paint linear = new Paint();
        linear.setColor(Color.WHITE);
        //圆点
        canvas.drawCircle(200, 750, 10, linear);
        canvas.drawCircle(300, 500, 10, linear);
        canvas.drawCircle(400, 650, 10, linear);
        canvas.drawCircle(500, 800, 10, linear);
        canvas.drawCircle(600, 450, 10, linear);
        //Y轴圆点
        canvas.drawCircle(100, 740, 10, linear);
        canvas.drawCircle(100, 580, 10, linear);
        canvas.drawCircle(100, 420, 10, linear);
        canvas.drawCircle(100, 260, 10, linear);
        canvas.drawCircle(100, 100, 10, linear);
        //X圆点
        canvas.drawCircle(100, 900, 10, linear);
        canvas.drawCircle(200, 900, 10, linear);
        canvas.drawCircle(300, 900, 10, linear);
        canvas.drawCircle(400, 900, 10, linear);
        canvas.drawCircle(500, 900, 10, linear);
        canvas.drawCircle(600, 900, 10, linear);

        //X轴文字
        Paint xtext = new Paint();
        xtext.setTextSize(30);
        xtext.setColor(Color.WHITE);
        canvas.drawText("0:0", 100, 950, xtext);
        canvas.drawText("5:00", 200, 950, xtext);
        canvas.drawText("10:00", 300, 950, xtext);
        canvas.drawText("15:00", 400, 950, xtext);
        canvas.drawText("20:00", 500, 950, xtext);
        canvas.drawText("25:00", 600, 950, xtext);
    }
}

布局中加入

   <com.bawei.lmx.zhoukao3_427.clinear.ClinearLayout
        android:id="@+id/cliearlayout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值