A Pie/Donut*/Ring chart for Android, customizable to the most extent possible.
For tutorial and examples refer to the website.
implementation("ir.mahozad.android:pie-chart:0.7.0")
<ir.mahozad.android.PieChart
android:id="@+id/pieChart"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
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)
)
@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
}
)
}
Please help improve the library by fixing the issues that I couldn't tackle myself.
Any other contributions are also welcome.
* Or Doughnut โต