MPAndroidChart代码套路记录

代码套路:

             

          1.Entry键值对,表示每一对值,如果是柱状图就是一根柱子x,y;


           2.然后list包装.


         3.dataset表示一堆数据,比如折线图就是表示一条线


         4.然后list包装

       

         5.放入data,如LineData



@Override
    public BarData buildData(DataEntity<List<BarEntry>> datas) {

        List<List<BarEntry>> entrys=datas.getEntrys();
        List<String> title=datas.getDataTitle();
        List<String> xAxiValue=datas.getxAxiValue();

        chart=datas.getChart();
        colors=datas.getColors();
        int size=datas.getEntrys().size();

        if(size!=datas.getDataTitle().size()){
            throw  new IllegalArgumentException("dataTitle !=entrys");
        }

        for(int i=0;i<size;i++){
            BarDataSet dataSet=new BarDataSet(entrys.get(i),title.get(i));
            barDataSets.add(dataSet);
        }

        barData=new BarData(xAxiValue,barDataSets);
        return barData;
    }
注:饼状图特殊,没一个Entry代表一个扇形,dataset只有一个。


渲染效果:

      dataset,data,chart都可以对图进行渲染,chart可以通过getLengend,getXAxis....对图进行设置。


注:在进行获取Y轴时要使用getLeftAxis,getRightAxis,

       饼状图的Entry的x轴值,虽然它是不存在的,但还是要从0开始传

     使用版本最好用

compile 'com.github.PhilJay:MPAndroidChart:v2.1.6'

    github上的最新版本有坑。


最后附上大神文章,超仔细

http://blog.csdn.net/u014136472/article/details/50381639



猜你喜欢

转载自blog.csdn.net/hanjuly9569/article/details/53809107