A .NET for Android binding by Lucas Teixeira for MPAndroidChart by Philipp Jahoda. https://github.com/PhilJay/MPAndroidChart
- Upstream's last tagged release is still v3.1.0 (April 2019), which is what package 3.1.0 binds. This
package binds master at 9c7275a0 (2025-06-05), the 63 commits made after the tag: the 2020 "catching
up to iOS" batch (
Fillgradients, pie highlight color, min/max axis label counts,clipDataToContent, no-data text alignment,dataIndexhighlighting for combined charts,ApproximatorN), the revert that brought theIValueFormatter/IAxisValueFormatterinterfaces back, and assorted bug fixes. Full upstream diff: https://github.com/PhilJay/MPAndroidChart/compare/v3.1.0...9c7275a0 - Targets net10.0-android (.NET 10 SDK, Android workload 36.1).
SupportedOSPlatformVersionis 21, the lowest .NET 10 supports; MPChartLib itself is compiled against API 28 withminSdkVersion 14and has no runtime dependencies (androidx.annotationis compile-time only). - The AAR is embedded in the assembly the .NET way (
AndroidLibrary), the assembly isIsTrimmable, and the C# doc comments come from the Java sources jar (JavaSourceJar) instead of the oldJavaDocs/folder. - Namespaces are unchanged:
com.github.mikephil.charting.*→MikePhil.Charting.*.
These are upstream's changes, the binding just follows them:
| 3.1.0 binding | 3.1.0.1 binding |
|---|---|
ValueFormatter abstract class (GetFormattedValue(float), GetAxisLabel, GetBarLabel, GetPieLabel, …) |
Removed. IValueFormatter.GetFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler vph) and IAxisValueFormatter.GetFormattedValue(float value, AxisBase axis) are back (the 3.0.x shape). Implement them on a Java.Lang.Object subclass. |
IDataSet.ValueFormatter / AxisBase.ValueFormatter typed ValueFormatter |
Typed IValueFormatter / IAxisValueFormatter. DefaultValueFormatter, LargeValueFormatter, PercentFormatter, StackedValueFormatter, IndexAxisValueFormatter implement the interfaces. |
PercentFormatter(PieChart) |
PercentFormatter() / PercentFormatter(DecimalFormat) |
GradientColor, BaseDataSet.GradientColor, GradientColors, GetGradientColor(int) |
MikePhil.Charting.Util.Fill (solid, gradient or Drawable), BarDataSet.Fills / SetFills, GetFill(int). GradientColor now derives from Fill; SetGradientColor(start, end) and SetGradientColors(IList<Fill>) still exist. |
DataSet.Values |
DataSet.Entries (Values is kept as a deprecated alias) |
DataRenderer.DrawValue(Canvas, string, float, float, int) (abstract) |
DrawValue(Canvas, IValueFormatter, float, Entry, int, float, float, int) |
Chart.HighlightValue(x, y, dataSetIndex[, callListener]) |
Plus HighlightValue(x[, y], dataSetIndex, dataIndex[, callListener]) and Highlight(x, y, dataSetIndex, dataIndex) for combined charts |
New since 3.1.0: AxisBase.AxisMinLabels / AxisMaxLabels, YAxis.LabelXOffset, Chart.SetNoDataTextAlignment,
BarLineChartBase.SetClipDataToContent, PieDataSet.HighlightColor, PieDataSet.SetUseValueColorForLine,
DataSet.Entries, ApproximatorN.
var entries = Enumerable.Range(0, 8).Select(i => new Entry(i, (float)(Math.Sin(i) * 10 + 20))).ToList();
var set = new LineDataSet(entries, "sin") { ValueFormatter = new TwoDecimals() }; // : Java.Lang.Object, IValueFormatter
set.SetMode(LineDataSet.Mode.CubicBezier);
set.SetColors(ColorTemplate.MaterialColors.ToArray());
chart.Data = new LineData(set);
chart.XAxis.ValueFormatter = new IndexAxisValueFormatter(new[] { "a", "b", "c" });
chart.SetOnChartValueSelectedListener(new MyListener()); // : Java.Lang.Object, IOnChartValueSelectedListenerSupport
var bars = new BarDataSet(barEntries, "bars") { Fills = new List<Fill> { new Fill(start, end), new Fill(solid) } };tools/SmokeTest/MainActivity.cs has a longer version of the above covering every chart type.
Requirements: .NET 10 SDK with the android workload and a JDK (11 or newer; the workload's configured JDK
is used). global.json pins the .NET SDK to 10.0.302.
dotnet build -c Release # produces bin/Release/MPAndroidChart.3.1.0.1.nupkgNUGET.md is the readme shown on nuget.org (install, quick start, upgrade notes); this file is for the repo.
Transforms/Metadata.xml carries the hand tweaks: the MikePhil.* namespaces, the *Support names for the
listener interfaces, Chart.Data typed as ChartData (Java declares it as the generic T), the IDataSet
generic overloads that the generator cannot bind, Chart.CalculateOffsets made public, and ILineDataSet.getMode
kept as GetMode() / SetMode() because Mode is also the nested enum. Additions/ supplies the two members
the generator leaves abstract: BarBuffer.Feed(Java.Lang.Object) and EntryXComparator.Compare(Object, Object).
tools/build-aar.sh [ref]clones PhilJay/MPAndroidChart atref(defaultmaster), buildsMPChartLibwith Gradle (upstream still uses AGP 7.0.4 / Gradle 7.2, so the script picks JDK 11 and needs theandroid-28platform installed) and copiesMPChartLib-release.aarandMPChartLib-sources.jarintoJars/.- Bump
<Version>and<PackageReleaseNotes>inMPAndroidChart.csproj, thendotnet build -c Release. Metadata rules that no longer match anything show up asBG8A00/BG8A04warnings; delete them. dotnet build tools/SmokeTestmust compile (it uses the formatter interfaces,Fill, the listener and theChart.Datafix).dotnet build tools/SmokeTest -t:Runinstalls and starts it on the connected emulator or device and shows every chart type.
Copyright 2016-2026 Lucas Teixeira & Philipp Jahoda
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.