画天气预报 折线图 源代码

本文详细介绍了如何使用编程语言绘制天气预报的折线图,从数据准备到图表展示,涵盖画布设置、坐标轴定义、数据点绘制等关键步骤,帮助读者理解并实现自己的天气变化可视化工具。
摘要由CSDN通过智能技术生成
package com.app.map.widget;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.widget.HorizontalScrollView;

import com.app.map.R;
import com.app.map.model.bean.PointBean;
import com.app.map.model.bean.WeatherBean;

import java.util.ArrayList;
import java.util.List;


public class weatherView extends HorizontalScrollView {

    private Context context;
    private Paint mPaint;
    private Rect mBound;
    private int itemWeight;
    private int itemSize = 0;
    private int width;
    private int height;
    private List<String> str;
    private List<Integer> tempOne;
    private List<Integer> tempTwo;
    private int tempMax = 0;
    private int tempMin = 0;
    private List<String> riqiStr;
    private List<String> weatherStrOne;
    private List<Bitmap> weatherImgOme;
    private List<Bitmap> weatherImgTwo;
    private List<String> weatherStrTwo;
    private List<String> windStr;
    private List<String> windLeverStr;
    private List<String> airQualityColor;
    private List<String> airQuality;
    private Canvas mCanvas;
    private static final int DRAW_ONE_PIC = 1001;
    private static final int DRAW_TWO_PIC = 1002;

    public weatherView(Context context) {
        super(context);
        this.context = context;
        initData();
    }

    public weatherView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        initData();
    }

    public weatherView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        initData();
    }

    private void initData() {
        mPaint = new Paint();
        mPaint.setTextSize(dip2px(context, 10));

        mBound = new Rect();

        itemWeight = dip2px(context, 55);//每一个的宽度
    }

    /**
     * 设置数据
     */
    public void setShowData(WeatherBean weatherBean) {
        itemSize = weatherBean.getWeekStr().size();//总共个数
        tempMax = weatherBean.getMaxTemp();//最大值
        tempMin = weatherBean.getMinTemp();//最小值
        str = weatherBean.getWeekStr();//星期
        riqiStr = weatherBean.getRiqiStr();//日期
        weatherStrOne = weatherBean.getWeatherStrOne();//天气
        weatherImgOme = weatherBean.getWeatherImgOme();//天气图片
        tempOne = weatherBean.getTempOne();//第一条温度数据
        tempTwo = weatherBean.getTempTwo();//第二条温度数据
        weatherImgTwo = weatherBean.getWeatherImgTwo();//天气图片
        weatherStrTwo = weatherBean.getWeatherStrTwo();//天气
        windStr = weatherBean.getWindStr();//风的类型
        windLeverStr = weatherBean.getWindLeverStr();//风的级别
        airQualityColor = weatherBean.getAirQualityColor();//质量背景色
        airQuality = weatherBean.getAirQuality();//质量
        invalidate();
    }

    @Override
    protected void onDraw(final Canvas canvas) {
        mCanvas = canvas;
        super.onDraw(canvas);
        width = getWidth();
        height = getHeight();
        //设置背景色
        setBackgroundColor(Color.parseColor("#88253643"));

        //画分割线
        mPaint.setColor(getResources().getColor(R.color.transparent_white_55));
        mPaint.setStrokeWidth(dip2px(context, 0.5f));
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值