Create Doughnut Chart Similar to Google Fit

≡放荡痞女 提交于 2019-12-09 16:26:46

问题


Does anyone know how to create a doughnut chart similar to the one in Google Fit. Is there a library for this?


回答1:


I also wanted this, but the best answer i could find was "make your own". So I did.

This is pretty basic (I'm new to android) and unfinished, but it should give you the idea.

Basically, you just set up your paint objects

    paintPrimary = new Paint();
    paintPrimary.setAntiAlias(true);
    paintPrimary.setColor(colorPrimary);
    paintPrimary.setStyle(Paint.Style.STROKE);
    paintPrimary.setStrokeCap(Paint.Cap.ROUND);

and call canvas.drawArc

class FitDoughnutView extends View {

    private RectF _oval;

    public FitDoughnutView(Context ctx) {
        super(ctx);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        canvas.drawArc(_oval, 0, 360, false, paintSecondary);

        canvas.drawArc(_oval, 270, percentDeg, false, paintPrimary);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        _oval = new RectF(width, width, w - width, h - width);
    }
}

Full source here: github.com/tehmantra/fitdoughnut

Someone's tutorial: hmkcode.com/android-canvas-how-to-draw-2d-donut-chart/




回答2:


I found this: https://github.com/txusballesteros/fit-chart

I hope this helps someone with the same problem.



来源:https://stackoverflow.com/questions/29281238/create-doughnut-chart-similar-to-google-fit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!