If you are a mobile app developer and love to use the Flutter framework, you’ll be thrilled to know that the Syncfusion Flutter Charts package is available on pub.dev.
The Syncfusion Flutter Charts package is a data-visualization library written natively in Dart for creating beautiful and high-performance charts for high-quality mobile app user interfaces for iOS and Android using the Flutter framework. It allows users to plot data and render the customized chart types with seamless interactions and responsively smooth animations.
Flutter is a Google’s mobile app development SDK that has widgets and tools for creating natively compiled cross-platform mobile applications from a single code base. Flutter has the following advantages over other cross-platform mobile app development frameworks:
Syncfusion Flutter charts are rich in features, including functionality for rendering Cartesian charts, circular charts, pyramid and funnel charts. They are completely customizable and extendable, and their feature lists will expand aggressively in upcoming updates. Have a look at the following current features.
The chart widget includes functionality for plotting 30+ series types:
Each chart type is easily configured with built-in support for creating stunning visual effects. You can add any number of series to the chart. Features such as markers, data labels, data label builder, animation, gradient fill, dashes, sorting, and annotations are easy to incorporate and customize.
Plot any type of data in a graph using these four axes types:
Axis features such as label intersecting, edge label placement, label rotation, axis opposition, inverse axis, and multiple axis allow users to customize axis elements further to make an axis more readable.
User experience is greatly enhanced by the following interaction features:
Display additional information about a chart series using legends. The chart legends can also be used to collapse the series. Legends can be wrapped or scrolled if items exceed the available bounds.
A chart can be updated dynamically with live data that changes in seconds, like stock prices, temperature, and speed (i.e., data points or series can be added or removed from the rendered chart dynamically). Also, the entire data source of the chart can be replaced completely.
We are planning to add more chart types, as well as richer charts, in future releases.
This section explains how to create a simple chart and demonstrates its basic usage.
Add the Syncfusion Flutter Charts dependency to your the pubspec.yaml file.
dependencies: syncfusion_flutter_charts: ^17.3.26
Run the following command to get the required packages.
$ flutter pub get
Import the following package in your Dart code.
import 'package:syncfusion_flutter_charts/charts.dart';
Add a chart widget as a child of any widget. Here, we are adding the chart widget as a child of the container widget.
@override Widget build(BuildContext context) { return Scaffold( body: Center( child: Container( child: SfCartesianChart( ) ) ) ); }
Based on your data, initialize the appropriate axis type and series type. In the series, you need to map the data source and the fields for x and y data points. Since we are going to render a line chart with a category axis, I have initialized them.
@override Widget build(BuildContext context) { return Scaffold( body: Center( child: Container( child: SfCartesianChart( primaryXAxis: CategoryAxis(), // Initialize category axis. series: <LineSeries<SalesData, String>>[ // Initialize line series. LineSeries<SalesData, String>( dataSource: [ SalesData('Jan', 35), SalesData('Feb', 28), SalesData('Mar', 34), SalesData('Apr', 32), SalesData('May', 40) ], xValueMapper: (SalesData sales, _) => sales.year, yValueMapper: (SalesData sales, _) => sales.sales ) ] ) ) ) ); } class SalesData { SalesData(this.year, this.sales); final String year; final double sales; }
Finally, add Syncfusion Flutter Charts elements such as title, legend data labels, and tooltips to display additional information about the data plotted in chart.
@override Widget build(BuildContext context) { return Scaffold( body: Center( child: Container( child: SfCartesianChart( primaryXAxis: CategoryAxis(), title: ChartTitle(text: 'Half yearly sales analysis'), //Chart title. legend: Legend(isVisible: true), // Enables the legend. tooltipBehavior: TooltipBehavior(enable: true), // Enables the tooltip. series: <LineSeries<SalesData, String>>[ LineSeries<SalesData, String>( dataSource: [ SalesData('Jan', 35), SalesData('Feb', 28), SalesData('Mar', 34), SalesData('Apr', 32), SalesData('May', 40) ], xValueMapper: (SalesData sales, _) => sales.year, yValueMapper: (SalesData sales, _) => sales.sales, dataLabelSettings: DataLabelSettings(isVisible: true) // Enables the data label. ) ] ) ) ) ); }
The following screenshot illustrates the chart rendered using the above code snippet.
If you want an in-depth learning experience on creating a complete Flutter app, read Flutter Succinctly by Ed Freitas. It’s a part of Syncfusion’s library of free technical ebooks.
Next, we are planning to implement Calendar and other data visualization widgets in Flutter and add chart types and usability features in the Charts widget.
We prioritize our development features and widgets based on developers’ needs. If you would like us to add a new widget, or if you have questions about our Flutter charts, please let us know in the comments section of this post.
In this blog post, we walked through our new Syncfusion Flutter Charts widget and discussed our future plans. We invite you to try out the widget and provide your feedback to make it more robust before its final release. As always, we are happy to assist you!
You can also contact us through our support forum, support portal, or feedback portal. This helps us prioritize the next set of controls and features to implement.