1.9 KiB
BarChart
To use the BarChart, follow the steps below:
- Include the Charty library in your Android project.
- Use the
BarChartcomposable 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
Parameters
BarChart accepts the following parameters:
-
dataCollection: AChartDataCollectionobject representing the data to be displayed in the bar chart. -
modifier: OptionalModifierto customize the appearance and behavior of the chart. -
barSpacing: OptionalDpvalue representing the spacing between bars in the chart. Default is8.dp. -
padding: OptionalDpvalue representing the padding around the chart. Default is16.dp. -
barColor: OptionalColorvalue representing the color of the bars in the chart. Default isColor.Blue. -
axisConfig: OptionalAxisConfigobject 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),
)