Android Canvas練習(9)自已繪分割突出效果的餅圖(Pie Chart)

來源:互聯網
上載者:User

這裡畫了個餅圖的變種,具有分割突出效果的餅圖(Pie Chart),就是個切蛋糕效果的餅圖,畫這種圖,其技巧就在於圓心的位移。

在圓心位移,半徑不變的基礎上,效果就出來了。

:

怎麼樣,效果還是有模有樣的吧。<喎?http://www.bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+ICAgICC0+sLruty88rWlo6y4vcnPOjwvcD4KPHA+ICAgICAgPHByZSBjbGFzcz0="brush:java;">package com.xcl.chart;/** * Canvas練習 * 自已繪分割突出效果的餅圖(Pie 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 PanelPieChart2 extends View{private int ScrWidth,ScrHeight; //示範用的百分比例,實際使用中,即為外部傳入的比例參數 private final float arrPer[] = new float[]{20f,30f,10f,40f}; //RGB顏色數組private final int arrColorRgb[][] = { {77, 83, 97}, {148, 159, 181}, {253, 180, 90}, {52, 194, 188}} ; //指定突出哪個塊private final int offsetBlock = 2;public PanelPieChart2(Context context) {super(context);// TODO Auto-generated constructor stub//螢幕資訊DisplayMetrics dm = getResources().getDisplayMetrics();ScrHeight = dm.heightPixels;ScrWidth = dm.widthPixels;}public void onDraw(Canvas canvas){//畫布背景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 PaintArc = new Paint(); Paint PaintLabel = new Paint(); PaintLabel.setColor(Color.WHITE);PaintLabel.setTextSize(16); //位置計算類 XChartCalc xcalc = new XChartCalc(); float Percentage = 0.0f; float CurrPer = 0.0f;int i= 0; for(i=0; i 代碼中只需注意下,指定要突出哪塊,就在哪塊上指定下位移即可。


附上我其它繪製的圖連結:

Android Canvas練習(1)畫一張報表來玩

Android Canvas練習(2)自已繪餅圖

Android Canvas練習(3)自已繪直條圖

Android Canvas練習(4)自已繪折線圖

Android Canvas練習(5)自已繪面積圖(Area Chart)

Android Canvas練習(7)繪製歐冠八強防守&控制率資料對比圖

Android Canvas練習(8)自已繪環形圖(Dount Chart)


MAIL: xcl_168@aliyun.com

BLOG: http://blog.csdn.net/xcl168


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.