Android Canvas exercise (8) Self-painted circular Chart (Dount Chart)

Source: Internet
Author: User

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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.