mp_flutter_chart 0.0.1
mp_flutter_chart: ^0.0.1 copied to clipboard
Flutter port of MPAndroidChart v4.0.1, class for class.
mp_flutter_chart #
A class-for-class Flutter port of MPAndroidChart v4.0.1:
the same class and member names as MPChartLib, pure Dart + dart:ui, running on Android, iOS and
HarmonyOS (OpenHarmony Flutter).
Status: Phase 0 (the LineChart vertical slice) is done, Phase 1 is in progress, and nothing is published yet. The package has the core
LineChartwith its data, axes, legend, renderers, highlighting, touch gestures, animations and viewport jobs, and the widget layer (LineChartwidget,ChartController,WidgetMarker,ChartHostWidget). Phase 1 has addedBarChart,HorizontalBarChart,ScatterChart,CandleStickChartandBubbleChart, each as a core chart class and as a widget. It has also addedPieChartandRadarChart, each as a core chart class and as a widget, rotated by touch and withspin;CombinedChartfollows in Phase 2. The LineChart was walked on the Android emulator, the iOS simulator and a HarmonyOS emulator in Phase 0 (docs/phase0-acceptance.md; on HarmonyOS an unsigned debug HAP installed withhdc, rendered with Skia). The five chart types fromBarCharttoBubbleChart, with the LineChart page again, were walked on the Android emulator, the iOS simulator and the HarmonyOS emulator (docs/phase1-acceptance-lane-a.md). That document links the side-by-side comparison with MPChartExample (docs/phase1-comparison-lane-a.md); the differences it traced to Phase 0 code are requests F1–F3 indocs/phase1/requests-lane-a.md. ThePieChartandRadarChartpages were walked on the Android emulator, the iOS simulator and the HarmonyOS emulator, and again from the example app's home list on the Android and HarmonyOS emulators (docs/phase1-acceptance-lane-c.md). API parity with MPChartLib is 1169/1169 symbols for the Phase 0 scope (docs/api-parity-phase0.md), and 167/167 (P1-A) and 131/131 (P1-B) for those five chart types (docs/api-parity-phase1-lane-a.md). ForPieChartandRadarChartit is 222/222 (P1-C,docs/api-parity-p1-c.md). Differences from Android are listed inMIGRATION.md.
Quick start #
import 'package:flutter/material.dart' hide Easing; // Material 3 has an `Easing` of its own
import 'package:mp_flutter_chart/mp_flutter_chart.dart';
class SalesChart extends StatefulWidget {
const SalesChart({super.key});
@override
State<SalesChart> createState() => _SalesChartState();
}
class _SalesChartState extends State<SalesChart> {
final controller = ChartController(); // optional: selection, zoom, animations
final data = LineData([
LineDataSet([Entry(x: 0, y: 3), Entry(x: 1, y: 5), Entry(x: 2, y: 4)], 'Sales')
..mode = LineDataSetMode.CUBIC_BEZIER,
]);
@override
void dispose() {
controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) => SizedBox(
height: 300,
child: LineChart(
data: data,
controller: controller,
// Runs once with the chart (a `LineChartView`, MPAndroidChart's `LineChart`) before the data is set.
setup: (chart) => chart.axisRight.isEnabled = false,
),
);
}
controller.animateX(1000), controller.fitScreen() and controller.selectedEntry (listen with a
ListenableBuilder) drive and read the chart. The BarChart and HorizontalBarChart (BarData), ScatterChart
(ScatterData), CandleStickChart (CandleData), BubbleChart (BubbleData), PieChart (PieData) and
RadarChart (RadarData) widgets take the same parameters; their setup and update get a BarChartView,
HorizontalBarChartView, ScatterChartView, CandleStickChartView, BubbleChartView, PieChartView or
RadarChartView. package:mp_flutter_chart/mp_flutter_chart.dart is the widget entry point;
package:mp_flutter_chart/core.dart has only the MPChartLib classes, where LineChart, BarChart and the other
chart names are the chart classes themselves. Import one of the two per file (both make the eight chart names
ambiguous), or core.dart with a prefix.
Decisions taken by default #
These five decisions were confirmed on 2026-10-16 (design spec §12):
- Baseline: MPAndroidChart v4.0.1 (the Kotlin rewrite), not 3.1.0 (Java).
- SDK floor: Flutter >= 3.35 / Dart >= 3.9, covering both the 3.35-ohos and 3.41-ohos lines (3.27/3.22-ohos are not supported).
- Package name:
mp_flutter_chart, to be published on pub.dev. - Example app scope: minimal set only — the Nightfall showcase, one page per chart type, an "animated changes" page and a "custom renderer" page.
- Platforms: Android / iOS / HarmonyOS first; Web and desktop must compile and support mouse drag (no scroll-wheel zoom in this release).
Development #
All commands go through tool/flutter.sh, which pins the HarmonyOS Flutter SDK
(/Users/jiaozi/code/ohos-flutter-3.41). Do not use the flutter on PATH.
tool/flutter.sh pub get
tool/flutter.sh analyze # the package; run it in example/ too: (cd example && ../tool/flutter.sh analyze)
tool/flutter.sh test # unit, widget, golden and perf tests
/Users/jiaozi/code/ohos-flutter-3.41/bin/dart run tool/api_parity.dart --scope=P0 --markdown=docs/api-parity-phase0.md
/Users/jiaozi/code/ohos-flutter-3.41/bin/dart run tool/api_parity.dart --scope=P1-A --markdown=docs/api-parity-p1-a.md
/Users/jiaozi/code/ohos-flutter-3.41/bin/dart run tool/api_parity.dart --scope=P1-B --markdown=docs/api-parity-p1-b.md
/Users/jiaozi/code/ohos-flutter-3.41/bin/dart run tool/api_parity.dart --scope=P1-C --markdown=docs/api-parity-p1-c.md
The last four commands regenerate the API parity reports against MPChartLib's API dump (tool/MPChartLib.api,
whitelist tool/api_whitelist.yaml), one per lane of the design spec's Appendix A; docs/api-parity-phase1-lane-a.md
sums up the first three. tool/api_parity.dart prints coverage: … and exits 0 with the report, also while a scored
symbol is missing; it exits 1 only with --fail-on-missing when a scored symbol is missing, and 2 on a bad argument
or an unreadable input (tool/README.md, "Exit codes").
Tests are tagged in dart_test.yaml:
golden:test/golden/compares against PNGs undertest/golden/goldens/macos/. Goldens are rendered by the host and only compared on macOS (the test is skipped elsewhere); regenerate them on macOS withtool/flutter.sh test --update-goldens test/golden.perf:test/perf/prints one timing line per case to stdout (first frame and redraws after a translate) for a 30 000-entry LineChart (LINEAR, andCUBIC_BEZIERwith fill), a 30 000-bar BarChart and a 100 000-candle CandleStickChart (the last two once lane A's chart classes are merged); the numbers are recorded indocs/perf-record.md, and there are no thresholds yet.
Skip either with --exclude-tags golden,perf.
Example #
example/ is a Flutter app (Android, iOS and HarmonyOS projects). Its home list follows MPChartExample's
MainActivity, with the same section and entry texts, and opens one page per entry: All chart types / Dark style and
Light style; Line Charts / Basic; Bar Charts / Basic, Multiple, Horizontal and Stacked; Pie Charts / Basic; Other
Charts / Scatter Plot, Bubble Chart, Candlestick and Radar Chart. Dark style and Light style open the port of
MPChartExample's DesignActivity: a card for each chart type ported so far, in the dark or light Nightfall style and
laid out in whole device pixels as Android lays out its XML, with a menu item that swaps the variant. The deep link
/design?dark=…&only=…&from=… opens it with DesignActivity's intent extras (example/README.md). The other pages
each show their chart in a ListView, in the dark Nightfall style of MPChartExample, with buttons for an animation,
zoomIn, fitScreen and an animated data switch; the bar, bubble and candlestick pages add buttons for options of
their chart type. The pie and radar pages have their own controls instead of the zoom and data buttons: the
PieChart page is a donut with Spin and switches for a half pie and for values outside the slices, the RadarChart
page two filled data sets with Animate, and both charts rotate by touch. Run it from example/ with
../tool/flutter.sh run. The acceptance walks are in docs/phase0-acceptance.md (Phase 0, on the Android emulator,
the iOS simulator and a HarmonyOS emulator) and docs/phase1-acceptance-lane-a.md (Phase 1, on all three);
docs/phase1-acceptance-lane-c.md has the walk of the pie and radar pages. On HarmonyOS, flutter run needs a debug
signing config from DevEco Studio; without one it builds the unsigned HAP and stops, and that HAP can be installed on
an emulator with hdc install (see docs/phase0-acceptance.md for the DEVECO_SDK_HOME / PATH settings).
MIGRATION.md's "Example app" section lists where the app differs from MPChartExample.
Upstream #
Ported from https://github.com/PhilJay/MPAndroidChart master as of 2026-10-16,
SHA fae4ad798564ea9ad494eaf037dca0e745400723; the source snapshot used for porting was fetched
from archive/refs/heads/master.tar.gz.
License #
Apache License 2.0. See LICENSE and NOTICE; the original MPAndroidChart copyright
(Philipp Jahoda, 2014-2026) is retained.