MPAndroidChart 4.0 is here: the library rewritten from the ground up in Kotlin, with a Jetpack Compose module. It is the first stable release since 3.1.0.
馃摉 Guides and documentation: philjay.cc/mpandroidchart 路 35 chapters from a first chart to theming, Compose, custom renderers and troubleshooting.
New in 4.0
- Kotlin first. Properties instead of getter and setter pairs, lambdas for formatters and listeners (
chart.onValueSelected { entry, highlight -> }), typed entry payloads, lists instead of arrays. Java callers keep working. - Jetpack Compose. The new
MPChartComposemodule: a composable for every chart type,ChartStateto read and drive a chart, and markers written as composables. - Animated data changes.
animateDataChange(newData)moves every value smoothly to its new one, andanimateValue(entry, toY)animates a single value. Every animation takes anonEndcallback, andisAnimatingandstopAnimations()are new. In Compose,animateChanges = trueanimates new data automatically. - Empty and loading states. A modern empty state with an outline of the chart type instead of the old yellow text, and
isLoadingfor data that is still on its way. Everything about it can be customized. - New styling. Rounded bars and stacked sections, rounded radar corners, a ring around the highlighted point, and highlight lines that can stop at the entry.
- Robust. Tested against NaN, Infinity, empty data and 100,000 entries, inside
RecyclerViewandLazyColumn, across rotation and with leak checks. More than 40 reported issues are fixed.
Faster
- Lines draw about 1.2x faster than in 3.1.0, and bars 1.6x faster with the new
isDecimationEnabled, which drops entries that share a pixel column. - A zoomed-in bar chart builds only the bars on screen: 2.5 ms per frame with 500 bars in view, whether the data holds 10,000 or 300,000.
- Line circles that would cover each other are skipped, and crowded candles are thinned out, so 100,000 entries draw in well under a second with default settings.
The performance chapter has all measurements.
Get it
// settings.gradle.kts
dependencyResolutionManagement {
repositories {
maven("https://jitpack.io")
}
}
// build.gradle.kts
dependencies {
implementation("com.github.PhilJay.MPAndroidChart:MPChartLib:v4.0.0")
implementation("com.github.PhilJay.MPAndroidChart:MPChartCompose:v4.0.0") // only for Compose
}minSdk 23 路 compileSdk 35 (37 for Compose) 路 Java 17 路 Kotlin 2.0 or newer. The getting started guide takes you from here to a first chart.
Upgrading
- From 3.x: class, package and interface names are unchanged, so imports survive and call sites change. The migration guide and MIGRATION.md cover every step. Projects on the 3.x coordinates keep building untouched.
- Staying on 3.x? Nothing changes for you. 3.2.0 is the last Java release with every fix from 3.x; coming from 3.1.0 it needs small formatter changes, which its notes list. The code lives on the
3.xbranch. - From 4.0.0-beta01: scatter shape sizes and
ComposeMarker.offsetare now in dp,centerTextSizePixelsis gone,PieData.dataSetis nullable andLargeValueFormatter.suffixis a list.
CHANGELOG.md lists every change. Thanks to everyone who reported issues and sent pull requests over the years.