/ComposePieChartView

Compose Pie Chart View Android

Primary LanguageKotlinMIT LicenseMIT

Contributors Forks Stargazers Issues MIT License LinkedIn

API Release


Logo

Kotlin Compose Pie Chart View

Simple and Lightweight Pie Chart View library written with Kotlin Compose.
Explore the docs »

View Demo · Report Bug · Request Feature

About The Project

Simple and Lightweight Pie Chart View library written with Kotlin Compose. Currently support Filled Pie Chart and Donut shaped pie chart styles. Offers wide range of customizations to the users. Checkout usages for more info.

Built With

  • Kotlin

Installation

  1. Add the JitPack repository to your root level build.gradle file.

    Groovy

dependencyResolutionManagement {
	repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
	repositories {
		mavenCentral()
		maven { url 'https://jitpack.io' }
	}
}

KTS

dependencyResolutionManagement {
	repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
	repositories {
		google()
		mavenCentral()
		maven { url = uri("https://jitpack.io") }
	}
}
  1. Add the dependency to you app level build.gradle file.

Latest version: Release

dependencies {
	implementation ("com.github.thilinakj:ComposePieChartView:$latest_release")
}

Usage

Use guide shows how Pie chart can be used for different scenarios with Jetpack Compose.

  1. Simple Filled Shaped Pie Chart Example

Logo

@Composable
fun SimpleFilledChartExample() {
    val records = listOf(
        PieChartData.Record(Color1, "A", 10.0),
        PieChartData.Record(Color2, "B", 20.0),
        PieChartData.Record(Color3, "C", 40.0),
    )
    PieChart(
        modifier = Modifier
            .fillMaxWidth(fraction = 0.4f),
        chartData = PieChartData(
            records = records,
            recordValueType = PieChartData.RecordValueType.RawData,
            chartType = PieChartData.ChartType.PieChartFilled,
        ),
    )
}
  1. Simple Donut Shaped Pie Chart Example

Logo

@Composable
fun SimpleDonutChartExample() {
    val records = listOf(
        PieChartData.Record(Color1, "A", 10.0),
        PieChartData.Record(Color2, "B", 20.0),
        PieChartData.Record(Color3, "C", 40.0),
    )
    PieChart(
        modifier = Modifier
            .fillMaxWidth(fraction = 0.4f),
        chartData = PieChartData(
            records = records,
            recordValueType = PieChartData.RecordValueType.RawData,
            chartType = PieChartData.ChartType.PieChartDonut(strokeWidth = 40.dp),
        ),
    )
} 
  1. Input Type Raw Data Chart Example

Logo

@Composable
fun InputTypeRawDataChartExample() {
    val records = mutableListOf(
        PieChartData.Record(Color5, "A", 10.0),
        PieChartData.Record(Color2, "B", 20.0),
        PieChartData.Record(Color3, "C", 40.0),
        PieChartData.Record(Color4, "D", 80.0),
        PieChartData.Record(Color1, "E", 160.0),
    )
    PieChart(
        modifier = Modifier
            .size(150.dp),
        chartData = PieChartData(
            records = records,
            recordValueType = PieChartData.RecordValueType.RawData,
            chartType = PieChartData.ChartType.PieChartFilled,
        ),
    )
}
  1. Input Type Angle Data Chart Example

Logo

val records = mutableListOf(
	PieChartData.Record(Color1, "A", 10.0),
	PieChartData.Record(Color2, "B", 20.0),
	PieChartData.Record(Color3, "C", 40.0),
	PieChartData.Record(Color4, "D", 80.0),
	PieChartData.Record(Color5, "E", 160.0),
	PieChartData.Record(Color6, "F", 50.0),
)
PieChart(
	modifier = Modifier
	    .size(150.dp),
	chartData = PieChartData(
	    records = records,
	    recordValueType = PieChartData.RecordValueType.Angle,
	    chartType = PieChartData.ChartType.PieChartFilled,
	),
)
  1. Input Type Percentage Data Chart Example

Logo

val records = mutableListOf(
        PieChartData.Record(Color1, "A", 10.0),
        PieChartData.Record(Color2, "B", 20.0),
        PieChartData.Record(Color3, "C", 40.0),
        PieChartData.Record(Color4, "D", 5.0),
        PieChartData.Record(Color5, "E", 15.0),
        PieChartData.Record(Color6, "F", 10.0),
    )
PieChart(
	modifier = Modifier
	    .size(150.dp),
	chartData = PieChartData(
	    records = records,
	    recordValueType = PieChartData.RecordValueType.Percentage,
	    chartType = PieChartData.ChartType.PieChartFilled,
	),
)
  1. Pie Chart With Fixed Size Example

Logo

Row(
	modifier = Modifier.fillMaxWidth(),
	horizontalArrangement = Arrangement.Center,
) {
	PieChart(
	    modifier = Modifier
		.size(100.dp),
	    chartData = PieChartData(
		records = getSampleRecordData(),
		recordValueType = PieChartData.RecordValueType.RawData,
		chartType = PieChartData.ChartType.PieChartFilled,
	    ),
	)
	PieChart(
	    modifier = Modifier
		.size(100.dp),
	    chartData = PieChartData(
		records = getSampleRecordData(),
		recordValueType = PieChartData.RecordValueType.RawData,
		chartType = PieChartData.ChartType.PieChartDonut(30.dp),
	    ),
	)
}
  1. Pie Chart With Adaptive Size Example

Logo

Row(
	verticalAlignment = Alignment.CenterVertically,
) {
	PieChart(
	    modifier = Modifier
		.weight(4f),
	    chartData = PieChartData(
		records = getSampleRecordData(),
		recordValueType = PieChartData.RecordValueType.RawData,
		chartType = PieChartData.ChartType.PieChartFilled,
	    ),
	)
	PieChart(
	    modifier = Modifier
		.weight(6f),
	    chartData = PieChartData(
		records = getSampleRecordData(),
		recordValueType = PieChartData.RecordValueType.RawData,
		chartType = PieChartData.ChartType.PieChartDonut(30.dp),
	    ),
	)
}

Roadmap

  • Clickable Chart Segments
  • Shadows and elavations

See the open issues for a full list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)