Creating Donut Charts Like Google Fit

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

Google fit chart

+6
source share
2 answers

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

It is pretty simple (I'm new to android) and unfinished, but it should give you this idea.

Basically, you just set up your drawing 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/

+3
source

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

I hope this helps someone with the same problem.

+2
source

Source: https://habr.com/ru/post/984271/


All Articles