Skip to content
HDCharts

Bar Chart

BarChart renders categorical values as vertical bars, positive or negative.

Bar Demo

The example below is minimal and runs as written. The GIF above uses a longer generated series; its full source is in BarExample.kt.

@Composable
fun ShowBar() {
    val data = listOf(45.0, -12.0, 38.0, 27.0, -19.0, 42.0, 31.0).toChartData(
        categories = listOf("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"),
        seriesName = "Net cash flow",
    )

    BarChart(data = data, title = "Daily Net Cash Flow")
}

Fixed Y-Axis Range

By default the Y-axis is derived from the data, which can make small fluctuations look exaggerated when the axis doesn't start at zero. Set range on BarChartDefaults.style() to pin min, max, or both, independently of one another; whichever bound you leave null keeps deriving from the data.

@Composable
fun ShowBarWithRange() {
    val data = listOf(45.0, -12.0, 38.0, 27.0, -19.0, 42.0, 31.0).toChartData(
        categories = listOf("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"),
        seriesName = "Net cash flow",
    )

    BarChart(
        data = data,
        title = "Daily Net Cash Flow",
        style = BarChartDefaults.style(
            range = BarChartDefaults.range(min = -50.0, max = 50.0),
        ),
    )
}

Gradients

Bars take a linear gradient through BarChartDefaults.bars(gradient = ...), covered in Gradients.

Setup

Add this chart to your project

Choose the target and dependency scope to generate a Gradle Kotlin DSL snippet.

Dependency

A commonMain dependency is shared with every consuming target. Use this only if HDCharts publishes compatible variants for all those targets; otherwise choose a supported platform source set.

kotlin {
    sourceSets {
        commonMain.dependencies {
            implementation("io.github.hdcharts:bar:3.0.0")
        }
    }
}

Uses the bar artifact, without pulling in every chart module.

Requires Maven Central in your Gradle dependency repositories.