zoukankan      html  css  js  c++  java
  • 第二阶段冲刺-07

    昨天主要是对饼状图进行学习,找到了一个相关的模板,可以实现从界面的输入框获取数据,并经过相关的计算,算出相应的角度,并调用方法绘制出饼状图
    遇到的问题:由于获取数据时是都需要调用hashmap中的数据,所以必须初始化,并且只能实现首先初始化,然后点击生成统计表实现饼状图的绘制
    今天准备做,对饼状图处理数据的方法进行研究,增加跟多的消费类型,并且对数据进行赋值,使其能够成功的绘制饼状图。



    private void initView() {
            mLny = findViewById(R.id.lnyOut);
            etCanyin = findViewById(R.id.etCanyin);
            etYule = findViewById(R.id.etWenjiao);
            etCHuxing = findViewById(R.id.etChuxing);
            etFushi = findViewById(R.id.etFushi);
            etShenghuo = findViewById(R.id.etShenghuo);
    
            btnUpdate = findViewById(R.id.btnUpdate);
            btnUpdate.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    uodatePieChart();
                }
            });
    
        }
    
    
        @RequiresApi(api = Build.VERSION_CODES.O)
        @Override
        protected void onResume() {
            super.onResume();
            myDataView = new MyDataView(this, DataDegree(), DataColor());
            params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT);
    
            mLny.addView(myDataView, params);
        }
    
        private HashMap<String , Float> DataDegree(){
            dataDegee.put("餐饮消费", 32f);
            dataDegee.put("文教娱乐", 42f);
            dataDegee.put("服饰美容", 52f);
            dataDegee.put("出行交通", 92f);
            dataDegee.put("其它",142f);
            dataDegee.put("1212",32f);
            return dataDegee;
        }
    
    
        @RequiresApi(api = Build.VERSION_CODES.O)
        private HashMap<String , String> DataColor(){
    
            dataColor.put("餐饮消费", "#6600ff");
            dataColor.put("文教娱乐", "#cc00ff");
            dataColor.put("服饰美容","#9933ff");
            dataColor.put("出行交通", "#ff9900");
            dataColor.put("其它","#9999ff");
            dataColor.put("1212","#ffff00");
            dataColor.put("","#0000ff");
            dataColor.put("","#00ff00");
            dataColor.put("","#800000");
    //        dataColor.put("","#800080");
    //        dataColor.put("","");
            return dataColor;
        }
    
        private void uodatePieChart(){
            month = (TextView)findViewById(R.id.month);
            String n = month.getText().toString();
            String[] a = n.split("[^0-9]");
    
            String year2 = a[0];
            String month2 = a[1];
    
            float canyin = Query(year2,month2,"餐饮");
            float yule = Query(year2,month2,"娱乐");
            float gouwu = Query(year2,month2,"购物");
            float chuxing = 50;
            float fushi = 86;
            float s = 58;
    
            float total = canyin +yule +fushi +gouwu +chuxing + 58;
    
            if(total>0){
    
                dataDegee.put("餐饮", getDegree(canyin,total));
                dataDegee.put("服饰美容", getDegree(fushi,total));
                dataDegee.put("其它", getDegree(gouwu,total));
                dataDegee.put("出行交通", getDegree(chuxing,total));
                dataDegee.put("娱乐", getDegree(yule,total));
                dataDegee.put("1212",total);
                mLny.removeView(myDataView);
                mLny.addView(myDataView, params);
                Log.i("test draw", "remove view ; add view");
                Toast.makeText(this,"哇,你居然在"+getMaxinumType()+"上花了这么多",Toast.LENGTH_SHORT).show();
    
            }else {
                Toast.makeText(this,"输入您的消费额度",Toast.LENGTH_SHORT).show();
            }
        }
    
        private float getDegree(float number, float total){
            return  number/total * 360;
        }
    
    
        private String getMaxinumType(){
            String type="";
            float money = Float.MIN_VALUE;
            for(String key : dataDegee.keySet()){
                if(dataDegee.get(key) > money){
                    type = key;
                    money = dataDegee.get(key);
                }
            }
            return type;
        }
    

      

  • 相关阅读:
    MySQL5.7.17解压版安装
    autocomplete初步使用
    前端面试题:驼峰体与匈牙利语法的相互转换
    前端常用正则表达式
    解决npm报错:Module build failed: TypeError: this.getResolve is not a function
    vue实现对语言的切换,结合vue-il8n。
    大量数据处理的一个思路
    不同格式矢量数据源在MapServer上发布服务后切片缓存效率对比
    CentOS7使用yum安装PostgreSQL和PostGIS
    ArcGIS消除图斑重叠错误
  • 原文地址:https://www.cnblogs.com/1gaoyu/p/10999703.html
Copyright © 2011-2022 走看看