根据数据库数据画饼图

 

 

       数据库传入数据为   (分类、该分类下消费金额)

 

       效果图:根据数据库数据画饼图_第1张图片

 

	private HashMap getMonthData()
	{
		HashMap map = new HashMap();
		ArrayListkindlist = (ArrayList) kdao.find();
		for(int i=0;icolors = new ArrayList();
		colors.add(Color.BLACK);
		colors.add(Color.BLUE);
		colors.add(Color.GRAY);
		colors.add(Color.DKGRAY);
		colors.add(Color.RED);
		colors.add(Color.GREEN);
		
		ArrayList colorlist= new ArrayList();
		for(int i=0;i map) 
	{
		        
	         CategorySeries series = new CategorySeries(title);
	         Set set = map.entrySet();
	         Iterator it = set.iterator();	         
	         Double sum = 0.0;
	         while(it.hasNext())
	         {
	        	 java.util.Map.Entry entry = (java.util.Map.Entry)it.next();
	        	 sum+=Double.parseDouble(entry.getValue().toString());
	         }
	         
	         it = set.iterator();
	         while(it.hasNext())
	         {
	        	 double hundred;
	        	 java.util.Map.Entry entry = (java.util.Map.Entry)it.next();
	        	 String key = entry.getKey().toString();
	        	 double value = Double.parseDouble(entry.getValue().toString());
	        	 if(sum>0)
	        	 {
	        		 hundred = value/sum*100;
	        		 
	        		 series.add(key+"  "+doubleFormat.format(hundred)+"%",value);
	        	 }
	        	 else series.add(key+"  "+"0%",value);
	         }
		     return series;
	}
	protected DefaultRenderer buildCategoryRenderer(ArrayList colorlist) 
	{
		         DefaultRenderer renderer = new DefaultRenderer();
		         
		         renderer.setLegendTextSize(23);//设置左下角表注的文字大小
		          renderer.setLabelsTextSize(28.0f);
		         renderer.setMargins(new int[] { 20, 30, 15,0 });
		         //margins - an array containing the margin size values, in this order: top, left, bottom, right
		         for (int i=0;i


 

你可能感兴趣的:(Android)