dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'com.github.lecho:hellocharts-library:1.5.8@aar'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher_round">
</ImageView>
<lecho.lib.hellocharts.view.PieChartView
android:id="@+id/piechart"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"></lecho.lib.hellocharts.view.PieChartView>
</LinearLayout>
package com.example.total;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import lecho.lib.hellocharts.model.PieChartData;
import lecho.lib.hellocharts.model.SliceValue;
import lecho.lib.hellocharts.util.ChartUtils;
import lecho.lib.hellocharts.view.PieChartView;
public class LoginActivity extends Activity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login_activity);
PieChartView piechart;
piechart = findViewById(R.id.piechart);
piechart.setViewportCalculationEnabled(true);
piechart.setChartRotation(360,true);
piechart.setChartRotationEnabled(true);
piechart.setCircleFillRatio(1);
int numValues = 3;
List<SliceValue> values = new ArrayList<>();
for (int i = 0; i < numValues; i++) {
SliceValue sliceValue = new SliceValue((float) (i+1), Color.parseColor("#33B5E5"));
sliceValue.setLabel("label"+i);
values.add(sliceValue);
}
PieChartData data = new PieChartData(values);
data.setHasLabelsOnlyForSelected(true);
piechart.setPieChartData(data);
}
}