Simple and Lightweight Pie Chart View library written with Kotlin Compose.
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
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.
-
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") }
}
}
- Add the dependency to you app level
build.gradle
file.
dependencies {
implementation ("com.github.thilinakj:ComposePieChartView:$latest_release")
}
Use guide shows how Pie chart can be used for different scenarios with Jetpack Compose.
- Simple Filled Shaped Pie Chart Example
@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,
),
)
}
- Simple Donut Shaped Pie Chart Example
@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),
),
)
}
- Input Type Raw Data Chart Example
@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,
),
)
}
- Input Type Angle Data Chart Example
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,
),
)
- Input Type Percentage Data Chart Example
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,
),
)
- Pie Chart With Fixed Size Example
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),
),
)
}
- Pie Chart With Adaptive Size Example
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),
),
)
}
- Clickable Chart Segments
- Shadows and elavations
See the open issues for a full list of proposed features (and known issues).
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!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE.txt
for more information.