Continue with the study of the general graph, and draw a circular Chart here (Dount Chart). It is very simple, and the circle is covered with small circles. Haha, as shown in the following example:
VcnPOiAgICAgICAgIDwvcD4KPHA + PHByZSBjbGFzcz0 = "brush: java;"> package com. xcl. chart;/*** Canvas exercise * Self-drawn circular Chart (Dount chart) ** author: xiongchuanliang * date: 2014-4-12 */import android. content. context; import android. graphics. canvas; import android. graphics. color; import android. graphics. paint; import android. graphics. rectF; import android. util. displayMetrics; import android. view. view; public class PanelDountChart2 extends View {private int ScrWidth, ScrHeight; // example of percentage used in the demo. In actual use, private final float arrPer [] = new float [] {20f, 30f, 10f, 40f }; // RGB color array private final int arrColorRgb [] [] ={{ 77, 83, 97 },{ 148,159,181 },{ 253,180, 90 },{ 52,194,188 }}; public PanelDountChart2 (Context context) {super (context); // TODO Auto-generated constructor stub // display information DisplayMetrics dm = getResources (). getDisplayMetrics (); ScrHeight = dm. heightPixels; ScrWidth = dm. widthPixels;} public void onDraw (Canvas canvas) {// canvas background Canvas. drawColor (Color. WHITE); float cirX = ScrWidth/2; float cirY = ScrHeight/3; float radius = ScrHeight/5; // 150; float arcLeft = cirX-radius; float arcTop = cirY-radius; float arcRight = cirX + radius; float arcBottom = cirY + radius; RectF arcRF0 = new RectF (arcLeft, arcTop, arcRight, arcBottom ); // Paint brush initialization Paint PaintArc = new Paint (); PaintArc. setAntiAlias (true); Paint PaintLabel = new Paint (); PaintLabel. setTextSize (22); canvas. drawText ("author: xiongchuanliang", 50, ScrHeight-280, PaintLabel); PaintLabel. setColor (Color. WHITE); PaintLabel. setTextSize (16); // class XChartCalc xcalc = new XChartCalc (); float Percentage = 0.0f; float CurrPer = 0.0f; int I = 0; for (I = 0; I
That's a lot of code. Therefore, a simple graph does not need a chart library.
The class used in the code can be found in my previous example.
Android Canvas exercise (1) Draw a report
Android Canvas exercise (2) Self-painted pie chart
Android Canvas exercise (3) Self-painted column chart
Android Canvas exercise (4) Self-drawing line chart
Android Canvas exercise (5) Area Chart)
MAIL: xcl_168@aliyun.com
BLOG: http://blog.csdn.net/xcl168