MPAndroidChart PieChart how to set label text?

前端 未结 5 593
忘了有多久
忘了有多久 2021-01-05 07:28

got the following code:

    Legend legend = mChart.getLegend();
    legend.setLabels(new String[]{\"aaaaa\", \"bbbbb\", \"ccccc\"});

This s

5条回答
  •  Happy的楠姐
    2021-01-05 07:49

    1)Add dependency to build.gradle app level compile 'com.github.PhilJay:MPAndroidChart:v2.1.0' 2)make function chartData

     private void chartData() {
    
            ArrayList entries = new ArrayList<>();
            entries.add(new Entry(50, 0));
            entries.add(new Entry(60, 1));
    
    
            final int[] piecolors = new int[]{
                    Color.rgb(183, 28, 28),
                    Color.rgb(27, 94, 32)};
    
            PieDataSet dataset = new PieDataSet(entries, "");
    
            ArrayList labels = new ArrayList();
            labels.add("Borrowing");
            labels.add("Pending");
    
    
            PieData data = new PieData(labels, dataset);
            dataset.setColors(ColorTemplate.createColors(piecolors)); //
            data.setValueTextColor(Color.WHITE);
            pieChart.setDescription("Description");
            pieChart.setData(data);
    
        }
    

    3)Call chartData() in onCreate()

提交回复
热议问题