• 家庭记账本(二)


    chart_view.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="10dp">
    
    
        <lecho.lib.hellocharts.view.LineChartView
            android:id="@+id/chart"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="20dp" />
    
    
    
    </LinearLayout>

    ChartActivity.java

    package com.example.family;
    
    import android.app.Activity;
    import android.os.Bundle;
    
    import androidx.annotation.Nullable;
    
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Map;
    import java.util.TreeMap;
    
    import lecho.lib.hellocharts.model.ChartData;
    import lecho.lib.hellocharts.model.Line;
    import lecho.lib.hellocharts.model.LineChartData;
    import lecho.lib.hellocharts.model.PointValue;
    import lecho.lib.hellocharts.model.ValueShape;
    import lecho.lib.hellocharts.util.ChartUtils;
    import lecho.lib.hellocharts.view.Chart;
    import lecho.lib.hellocharts.view.LineChartView;
    
    public class ChartsActivity extends Activity {
    
        private LineChartView mChart;
        private Map<String,Integer> table=new TreeMap<>();
        private LineChartData mData;
    
        @Override
        protected void onCreate(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.chart_view);
            mChart=(LineChartView) findViewById(R.id.chart);
            mData=new LineChartData();
            List<CostBean> allDate= (List<CostBean>) getIntent().getSerializableExtra("cost_list");
            generateValues(allDate);
            generateData();
        }
    
        private void generateData() {
            List<Line> lines=new ArrayList<>();
            List<PointValue> values=new ArrayList<>();
            int indexX=0;
            for (Integer value:table.values()){
                values.add(new PointValue(indexX,value));
                indexX++;
            }
            Line line=new Line(values);
            line.setColor(ChartUtils.COLORS[0]);
            line.setShape(ValueShape.CIRCLE);
            line.setPointColor(ChartUtils.COLORS[1]);
            lines.add(line);
            mData =new LineChartData(lines);
            mData.setLines(lines);
            mChart.setLineChartData(mData);
        }
    
        private void generateValues(List<CostBean> allDate) {
            if(allDate!=null){
                for(int i=0;i<allDate.size();i++){
                    CostBean costBean=allDate.get(i);
                    String costDate=costBean.costDate;
                    int costMoney=Integer.parseInt(costBean.costMoney);
                    if (!table.containsKey(costDate)){
                        table.put(costDate,costMoney);
                    }else{
                        int originMoney=table.get(costDate);
                        table.put(costDate,originMoney+costMoney);
                    }
                }
            }
        }
    }
  • 相关阅读:
    Git工具简介
    Windows10搭建开发环境----Maven工具安装
    SpringBoot----01.SpringBoot基本配置
    创建一个SpringBoot项目
    软件工程----02. 需求分析
    软件工程----01. 软件工程简介
    JavaSE----11.Java 内部类
    JavaSE----10.Java 面向对象
    JavaSE----09.Java 数组
    前端面试总结
  • 原文地址:https://www.cnblogs.com/wangdayang/p/14913904.html
Copyright © 2020-2023  润新知