创建类似于Google Fit的甜甜圈图 [英] Create Doughnut Chart Similar to Google Fit
本文介绍了创建类似于Google Fit的甜甜圈图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人知道如何创建类似于Google Fit的甜甜圈图.
Does anyone know how to create a doughnut chart similar to the one in Google Fit.
推荐答案
我也想要这个,但是我能找到的最佳答案是自己制作".所以我做到了.
I also wanted this, but the best answer i could find was "make your own". So I did.
这是非常基本的内容(我是android的新手),尚未完成,但应该可以为您提供想法.
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);
并调用canvas.drawArc
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);
}
}
此处的完整来源: github.com/tehmantra/fitdoughnut
某人的教程: hmkcode.com/android-canvas-how-to-draw-2d-donut-chart/
这篇关于创建类似于Google Fit的甜甜圈图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文