开发者

How to draw Pie Chart Manually?

I need to draw the Pie Chart Manually .I need some basic Ideas to do that.Can any开发者_如何学运维one help Me ??


      public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         DemoView demoView=new DemoView(getBaseContext());
         setContentView(demoView);
      }

     private class DemoView extends View{
       public DemoView(Context context){
        super(context);
       }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        RectF mBigOval = new RectF(40, 10, 280, 250);
        Paint p = new Paint();
        DashPathEffect dashPath = new DashPathEffect(new float[]{5,5}, (float)1.0);
        PathEffect path=new PathEffect();
        p.setPathEffect(path);
        p.setStyle(Style.FILL_AND_STROKE);
        p.setColor(android.graphics.Color.GREEN);
        canvas.drawArc(mBigOval, 0, 360, true, p);
        p.setColor(Color.RED);
        canvas.drawArc(mBigOval, 0, 240, true, p);


        invalidate();
    }
}

try this code


Here is an example in Java (not for Android). You could easily port it for Android by using a Canvas instead of Graphics2D object. Instead of fillArc for example, you would use drawArc.


Create your own custom View class and implement the onDraw method to draw the chart using ArcShape.

You can then include your chart component in a layout just as you would one of the built-in components.


I've created a library to do what you are looking for (https://github.com/saulpower/ExpandablePieChart).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜