ir.mahozad.android:pie-chart

A library for creating pie charts and donut charts in Android. The aim of this library is to provide a full-featured chart view and to enable users to customize it to the most extent possible. Visit the project on GitHub to learn more.


Keywords
android, android-library, chart, charting, charting-library, donut-chart, donutchart, doughnut-chart, pie-chart, piechart, plotting, ring-chart, ringchart, visualization
License
Apache-2.0

Documentation

Release workflow Codecov Latest Maven Central release

Screenshot 1 Screenshot 2 Screenshot 3 Screenshot 4 Screenshot 5
Screenshot 2 Screenshot 1 Screenshot 3 Screenshot 4 Screenshot 5

A Pie/Donut*/Ring chart for Android, customizable to the most extent possible.
For advanced customizations like the screenshots above, 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
        }
    )
}

Contributing

Please help improve the library by fixing the issues that I couldn't tackle myself.
Any other contributions are welcome too.


* Or Doughnut ↵