雷达图
修改你的 build.gradle
文件
//root project
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
//module project
dependencies {
implementation 'com.github.android-zj:MRadarView:1.0.2'
}
使用方法
public class MainActivity extends AppCompatActivity {
MRadarView radarView;
private String tagName[] = new String[]{"金钱", "击杀", "物理", "魔法", "防御", "生存"};
private int tagPercent[] = new int[]{5,2,3,1,4,6};
private List<String> list = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
private void initView() {
radarView = findViewById(R.id.radarView);
addTagList();
}
private void addTagList() {
for (int i = 0; i < tagName.length; i++) {
list.add(tagName[i]);
}
radarView.setCount(list.size()); //设置多边形数量
//多边形tag
CharSequence[] csTag = list.toArray(new CharSequence[list.size()]);
radarView.setTitles(csTag);
setRegionShader(); //绘制网格
double max = tagPercent[0];
for (int i = 0; i < tagPercent.length; i++) {
if (tagPercent[i] > max) {
max = tagPercent[i];
}
}
double [] percent = new double[list.size()];
// radarView.setValues(tagValues.toArray(new CharSequence[tag.length]));
if (max == 0) {
radarView.setPointRadius(0);
} else {
for (int i = 0; i < tagPercent.length; i++) {
percent [i] = (tagPercent[i] / max);
// Log.v("AttributeEFragment", "tagPercent---i="+(tagList.get(i).getVal()/ max));
}
}
radarView.setPercents(percent);
}
//设置内圈颜色
private void setRegionShader() {
radarView.setColors(null);
if (radarView.getColors() != null) {
return;
}
radarView.setEnabledRegionShader(true);
}
}