Reputation: 411
What I have done: I'm using the MPAndroidChart and I was able to customize it to my requirement and tried further functionalities to remove Description Label, and to increase the font and customize the legend. What I have is now ;
<com.github.mikephil.charting.charts.PieChart
android:id="@+id/chart"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
>
</com.github.mikephil.charting.charts.PieChart>
public class PFrag extends Fragment {
float time[] = {55, 95, 30 , 360 - (55+95+30)};
String activity[] ={"Jan","Feb","March",""};
PieChart pieChart;
CircularProgressIndicator circularProgress;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.panorama_frag,container,false);
pieChart = view.findViewById(R.id.chart);
setupPieChart();
//circularProgress = view.findViewById(R.id.circular_progress);
// circularProgress.setMaxProgress(10000);
// circularProgress.setCurrentProgress(5000);
return view;
}
private void setupPieChart(){
//pupulating list of PieEntires
List<PieEntry> pieEntires = new ArrayList<>();
for( int i = 0 ; i<time.length;i++){
pieEntires.add(new PieEntry(time[i],activity[i]));
}
PieDataSet dataSet = new PieDataSet(pieEntires,"");
dataSet.setColors(ColorTemplate.MATERIAL_COLORS);
PieData data = new PieData(dataSet);
//Get the chart
pieChart.setData(data);
pieChart.invalidate();
pieChart.setCenterText("50% \n ");
pieChart.setDrawEntryLabels(false);
pieChart.setContentDescription("");
//pieChart.setDrawMarkers(true);
//pieChart.setMaxHighlightDistance(34);
pieChart.setEntryLabelTextSize(12);
pieChart.setHoleRadius(75);
//legend attributes
Legend legend = pieChart.getLegend();
legend.setForm(Legend.LegendForm.CIRCLE);
legend.setTextSize(12);
legend.setFormSize(20);
legend.setFormToTextSpace(2);
}
}
What I'm looking for: Though I tried it seems unable to find a way to edit the below functionalities.
Simply what I'm looking for is a graph like below.
To achieve that I used MPAndoridChart library after some searching and stuck here. I'm using Android Studio 3.6.1. I would really appreciate any suggestion on this.
Thank you!
I was able to solve below two queries:
How to remove the "Description Label" in the right-left corner
pieChart.getDescription().setEnabled(false);
How to increase the text size of the chart? > add
data.setValueTextSize(10);
Upvotes: 7
Views: 9918
Reputation: 21
To remove label inside data just use
dataSet.setDrawValues(false)
Upvotes: 2