To use the BarChart, follow the steps below:
- Include the Charty library in your Android project.
- Use the
BarChart
composable in your code:
fun BarChart(
dataCollection: ChartDataCollection,
modifier: Modifier = Modifier,
barSpacing: Dp = 8.dp,
padding: Dp = 16.dp,
axisConfig: AxisConfig = ChartDefaults.axisConfigDefaults(),
) {
// Implementation details...
}
or
fun BarChart(
dataCollection: ChartDataCollection,
modifier: Modifier = Modifier,
barSpacing: Dp = 8.dp,
padding: Dp = 16.dp,
barColor: Color = Color.Blue,
axisConfig: AxisConfig = ChartDefaults.axisConfigDefaults(),
){
// Implementation details...
}
In the above BarChart
, we have barColor
that will override the individual BarData's color
BarChart
accepts the following parameters:
-
dataCollection
: AChartDataCollection
object representing the data to be displayed in the bar chart. -
modifier
: OptionalModifier
to customize the appearance and behavior of the chart. -
barSpacing
: OptionalDp
value representing the spacing between bars in the chart. Default is8.dp
. -
padding
: OptionalDp
value representing the padding around the chart. Default is16.dp
. -
barColor
: OptionalColor
value representing the color of the bars in the chart. Default isColor.Blue
. -
axisConfig
: OptionalAxisConfig
object representing the configuration of the chart axes. Default isChartDefaults.axisConfigDefaults()
.
Where, AxisConfig looks like,
data class AxisConfig(
val showAxes: Boolean,
val showGridLines: Boolean,
val showGridLabel: Boolean,
val axisStroke: Float,
val minLabelCount: Int,
val axisColor: Color,
val gridColor: Color = axisColor.copy(alpha = 0.5F),
)