A Pie/Donut*/Ring chart for Android, customizable to the most extent possible.
For tutorial and examples refer to the website.
build.gradle[.kts]
implementation("ir.mahozad.android:pie-chart:0.7.0")
XML layout
<ir.mahozad.android.PieChart
android:id="@+id/pieChart"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Kotlin Activity
val pieChart = findViewById<PieChart>(R.id.pieChart)
pieChart.slices = listOf(
PieChart.Slice(0.2f, Color.BLUE),
PieChart.Slice(0.4f, Color.MAGENTA),
PieChart.Slice(0.3f, Color.YELLOW),
PieChart.Slice(0.1f, Color.CYAN)
)
Jetpack Compose
@Composable
fun PieChartView() {
AndroidView(
modifier = Modifier.fillMaxSize(),
factory = { context ->
PieChart(context).apply {
slices = listOf(
PieChart.Slice(0.2f, Color.BLUE),
PieChart.Slice(0.4f, Color.MAGENTA),
PieChart.Slice(0.3f, Color.YELLOW),
PieChart.Slice(0.1f, Color.CYAN)
)
}
},
update = { view ->
// View's been inflated or state read in this block has been updated
// Add logic here if necessary
}
)
}
Screenshots
Contributing
Please help improve the library by fixing the issues that I couldn't tackle myself.
Any other contributions are welcome too.
* Or Doughnut ↵