Coder Social home page Coder Social logo

mradarview's Introduction

MRadarView

雷达图

image

使用

修改你的 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);
    }

}

mradarview's People

Contributors

android-zj avatar

Stargazers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.