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;
        }
    

      

  • 相关阅读:
    fedora上部署ASP.NET——(卡带式电脑跑.NET WEB服务器)
    SQL Server 请求失败或服务未及时响应。有关详细信息,请参见事件日志或其它适合的错误日志
    8086CPU的出栈(pop)和入栈(push) 都是以字为单位进行的
    FTP 服务搭建后不能访问问题解决
    指定的 DSN 中,驱动程序和应用程序之间的体系结构不匹配
    Linux 安装MongoDB 并设置防火墙,使用远程客户端访问
    svn Please execute the 'Cleanup' command. 问题解决
    .net 操作MongoDB 基础
    oracle 使用绑定变量极大的提升性能
    尝试加载 Oracle 客户端库时引发 BadImageFormatException。如果在安装 32 位 Oracle 客户端组件的情况下以 64 位模式运行,将出现此问题。
  • 原文地址:https://www.cnblogs.com/1gaoyu/p/10999703.html
Copyright © 2011-2022 走看看