Quick Start#
This guide takes you from zero to a rendered chart in under two minutes.
Minimal bar chart#
import androidx.compose.foundation.layout.fillMaxWidthimport androidx.compose.foundation.layout.heightimport androidx.compose.ui.Modifierimport androidx.compose.ui.unit.dpimport com.himanshoe.charty.bar.BarChartimport com.himanshoe.charty.bar.data.BarDataBarChart( data = { listOf( BarData(label = "Jan", value = 120f), BarData(label = "Feb", value = 95f), BarData(label = "Mar", value = 160f), BarData(label = "Apr", value = 80f), BarData(label = "May", value = 200f), ) }, modifier = Modifier .fillMaxWidth() .height(300.dp),)data is always a lambda (() -> List<BarData>), not a bare list. This
lets Charty skip unnecessary recompositions when the surrounding state changes.
Customising the colour#
Use ChartyColor.Solid for a flat colour or ChartyColor.Gradient for a
multi-stop gradient. ChartyColors provides a ready-made palette of named
constants.
import com.himanshoe.charty.color.ChartyColorimport com.himanshoe.charty.color.ChartyColorsimport androidx.compose.ui.graphics.Color// Solid colour from the built-in paletteBarChart( data = { myData }, color = ChartyColor.Solid(ChartyColors.Blue), // Material Blue 500)// Custom solid colourBarChart( data = { myData }, color = ChartyColor.Solid(Color(0xFF6200EE)),)// Two-stop gradient (top → bottom)BarChart( data = { myData }, color = ChartyColor.Gradient( listOf(ChartyColors.Blue, ChartyColors.Teal) ),)Available ChartyColors constants: Blue, Red, Green, Orange, Purple,
Pink, Teal, Cyan, Indigo, Amber. Pre-built gradients:
DefaultGradient, DefaultMultiline, ModernPalette, WarmPalette,
CoolPalette, NaturePalette.
Enabling animation#
Pass an Animation value inside BarChartConfig. Three presets are available:
import com.himanshoe.charty.bar.config.BarChartConfigimport com.himanshoe.charty.common.config.AnimationBarChart( data = { myData }, barConfig = BarChartConfig( animation = Animation.Default, // 800 ms tween (recommended) // animation = Animation.Fast, // 400 ms // animation = Animation.Slow, // 1 200 ms // animation = Animation.Smooth, // physics-based spring // animation = Animation.Bouncy, // spring with a gentle bounce // animation = Animation.Enabled(duration = 600), // custom tween // animation = Animation.Disabled, // no animation ),)animation drives the chart's entry reveal. To also tween whenever the data changes, set animateValueChanges = true alongside it:
BarChart( data = { liveData }, barConfig = BarChartConfig( animation = Animation.Fast, animateValueChanges = true, ),)Handling clicks#
Supply a lambda to onBarClick. It receives the BarData of the tapped bar.
BarChart( data = { myData }, onBarClick = { barData -> println("Tapped: ${barData.label} = ${barData.value}") },)Putting it all together#
BarChart( data = { listOf( BarData(label = "Jan", value = 120f), BarData(label = "Feb", value = 95f), BarData(label = "Mar", value = 160f), ) }, modifier = Modifier .fillMaxWidth() .height(300.dp), color = ChartyColor.Gradient( listOf(ChartyColors.Blue, ChartyColors.Teal) ), barConfig = BarChartConfig( animation = Animation.Default, showDataLabels = true, ), onBarClick = { barData -> println("Tapped: ${barData.label} = ${barData.value}") },)A line chart with interactions#
import com.himanshoe.charty.common.gesture.ChartCrosshairimport com.himanshoe.charty.line.LineChartimport com.himanshoe.charty.line.config.LineChartConfigimport com.himanshoe.charty.common.config.LineInterpolationLineChart( data = { priceData }, modifier = Modifier.fillMaxWidth().height(300.dp), color = ChartyColor.Solid(ChartyColors.Blue), lineConfig = LineChartConfig( interpolation = LineInterpolation.SMOOTH, downsampleThreshold = 800, // stay smooth over very large series ), crosshair = ChartCrosshair(), // draggable guide line + label)Next steps#
Guides#
- Streaming and live data — rolling windows, scrollback, and "jump to latest".
- Exporting charts as PNG — capture and share a chart on every platform.
- Datetime axis and localization — smart time ticks, translated and reformatted.
- Synced crosshair — one guide line across a stack of charts.
Reference#
- More charts — explore
LineChart,PieChart,StackedBarChart, and 20 other chart types in the chart reference. - Common configuration — axes, grid, reference lines, tooltips, markers, and rolling windows.
- Interactions — crosshair, zoom/pan, brush selection, and which gestures can share a chart.
- Colors and animations —
ChartyColor, the palette, and theAnimationtype. - Theming — map your design system's colors, typography, shapes, and metrics onto every chart at once.
- Accessibility — provide a custom content description through
ChartInteractionConfig.accessibilityDescription.