android-compose-charts
This is an open source library used to draw charts in Android with Jetpack Compose with a simple and easy to use. Just couples of lines.
Usage:
-
Add this line to your project
gradle
file:maven { url 'https://jitpack.io' }
-
Add this dependency to your app
gradle
file:implementation 'com.github.MahmoudIbrahim3:android-compose-charts:
'
1. Bar Chart:
val barChartData = listOf(
BarChartEntity(150.0f, Color(0xFF618A32), "1"),
BarChartEntity(450.0f, Color(0xFFC32A33), "2"),
BarChartEntity(300.0f, Color.Blue, "3"),
BarChartEntity(150.0f, Color.Cyan, "4"),
BarChartEntity(500.0f, Color.Magenta, "5")
)
val verticalAxisValues = listOf(0.0f, 100.0f, 200.0f, 300.0f, 400.0f, 500.0f)
BarChart(
barChartData = barChartData,
verticalAxisValues = verticalAxisValues
)
The following code snippet demonstrates a lot of attributes to custom and design your Bar Chart as you like:
BarChart(
barChartData = barChartData,
verticalAxisValues = verticalAxisValues,
axisColor = Color.Red,
verticalAxisLabelColor = Color.Blue,
verticalAxisLabelFontSize = 20.sp,
horizontalAxisLabelColor = Color.Magenta,
horizontalAxisLabelFontSize = 24.sp,
paddingBetweenBars = 16.dp,
isShowVerticalAxis = true,
isShowHorizontalLines = false,
)
Bar Chart Samples:
2. Line Chart:
val lineChartData = listOf(
LineChartEntity(150.0f, "A"),
LineChartEntity(250.0f, "B"),
LineChartEntity(50.0f, "C"),
LineChartEntity(300.0f, "D"),
LineChartEntity(400.0f, "E")
)
LineChart(
lineChartData = lineChartData,
verticalAxisValues = verticalAxisValues
)
Custom attributes:
LineChart(
lineChartData = lineChartData2,
verticalAxisValues = verticalAxisValues2,
lineColor = Color.Red,
strokeWidth = 6.dp,
axisColor = Color(0xF0E47A8A),
verticalAxisLabelColor = Color.Blue,
verticalAxisLabelFontSize = 20.sp,
horizontalAxisLabelColor = Color.Black,
horizontalAxisLabelFontSize = 20.sp,
isShowVerticalAxis = true,
isShowHorizontalLines = true,
)