将一串字符按照不同名称分组,用于统计

                //工具map
                String classnamestr = "dfdsf,sdfsd,sfdsd,xss";
                String[] chs = classnamestr.split(",");
                Map<String,Integer> map = new TreeMap<String,Integer>();
                for (int i = 0; i < chs.length; i++) {
                    //将数组中的字母作为键去查map表。         
                    Integer value = map.get(chs[i]);
                    int count = 1;
                    //判断值是否为null.
                    if(value!=null){
                        count = value+1;
                    }
                    map.put(chs[i], count);
                }
                Iterator<String> it = map.keySet().iterator();
                
                int len = map.size(); 
                String[] itemname = new String[len];
                String[] data = new String[len];
                int num = 0;
                while(it.hasNext()){
                    String key = it.next();
                    Integer value = map.get(key);
                    itemname[num] = key;
                    data[num] = value+"";
                    num ++;
                }            
                
                /** 应用场景:海能图表 **/
                chart.setTitle("统计结果饼状图");//图表主标题 
                chart.setDataItemName(itemname);//设置进chart
                chart.addSeries("饼图数据", data, "PIE");//将数据设置进chart

 

你可能感兴趣的:(分组)