搜索插件、代码仓与 APP 分类

flutter_echarts 封面
插件详情v2.5.0

flutter_echarts

一个基于 Apache ECharts 的数据可视化图表库,能够构建高级图表,如 WebGL 3D、GIS 地图等。

AndroidiOSmacOS
近 30 天下载
5490
喜欢数
578
Pub 分数
130

安装插件

flutter pub add flutter_echarts

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

flutter_echarts 是一个功能强大的数据可视化库,基于 Apache ECharts 构建。它使开发者能够创建高级图表,如 WebGL 3D 可视化和交互式 GIS 地图。该包支持多种平台,包括 Android、iOS 和 macOS,为 Flutter 应用提供丰富且动态的图表功能。通过简单的 pub 命令即可实现无缝集成,非常适合需要高性能、功能丰富的数据展示的应用程序。

适合场景

  • 交互式仪表板
  • 地理空间数据映射
  • 3D 数据可视化
  • 实时分析显示
  • 移动应用中的复杂图表渲染

主要特点

  • 支持 WebGL 3D 图表
  • 内置GIS地图集成
  • 高性能渲染
  • 跨平台兼容性
  • 丰富的图表类型

适合对象

  • 数据密集型应用
  • 分析平台
  • 移动GIS工具
  • 工程和科学应用程序
  • 企业仪表板开发

使用建议

  • 需要了解 ECharts 配置
  • 由于捆绑了资源,可能会增加应用大小
  • 性能取决于设备硬件
  • 有限的原生 Flutter 小部件集成
  • 初学者的学习曲线更陡峭

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Archiving Note

After many years, this project, as a transitional solution using Webview, has completed its historical mission and is therefore being archived. We recommend Graphic or other native chart libraries as alternatives.

中文

*A Flutter widget to use [Apache ECharts](https://github.com/apache/incubator-echarts) in a reactive way.*

Features

Reactive Updating

The most exciting feature of Flutter widgets and React components is that the view can update reactively when data changes. Thanks to ECharts' data driven architecture, flutter_echarts implements a reactive way to connect charts with data. The charts automatically re-render when data in the option property changes.

Two Way Communication

The onMessage and extraScript properties provide a way to set two-way event communication between Flutter and JavaScript.

Configurable Extensions

ECharts has a lot of extensions. The extensions property allows you to inject the extension scripts as raw strings. In this way, you can copy these scripts to your source code without being confusing by assets dirs.

Installing

Add this to your package's pubspec.yaml file:

dependencies:
  flutter_echarts: #latest version

Now in your Dart code, you can use:

import 'package:flutter_echarts/flutter_echarts.dart';  

Details see pub.dev.

Usage

The flutter_echarts package itself is very simple to use, just like a common statelessWidget:

Details about the option object is in the Echarts docs or Echarts examples.

Container(
  child: Echarts(
  option: '''
    {
      xAxis: {
        type: 'category',
        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
      },
      yAxis: {
        type: 'value'
      },
      series: [{
        data: [820, 932, 901, 934, 1290, 1330, 1320],
        type: 'line'
      }]
    }
  ''',
  ),
  width: 300,
  height: 250,
)

See the full flutter_echarts_example.

bar boxplot effectScatter funnel gague geo graph heatmap kline line liquid map parallel pie radar scatter wordCloud bar3D line3D sankey scatter3D surface3D themeRiver overlap

Widget Properties

option

String

( required )

ECharts is mainly configured by passing a string value to the JavaScript option property.

You can use jsonEncode() function in dart:convert to convert data in Dart object form:

source: ${jsonEncode(_data1)},

Because JavaScript don't have ''', you can use this operator to reduce some escape operators for quotas:

Echarts(
  option: '''
  
    // option string
    
  ''',
),

To use images in option properties, we suggest the Base64 Data URL :

image: 'data:image/png;base64,iVBORw0KG...',

extraScript

String

JavaScript which will execute after the Echarts.init() and before any chart.setOption(). The widget has a Javascript channel named Messager, so you can use this identifier to send messages from JavaScript to Flutter:

extraScript: '''
  chart.on('click', (params) => {
    if(params.componentType === 'series') {
        Messager.postMessage('anything');
    }
  });
''',

onMessage

void Function(String)?

Function to handle the message sent by Messager.postMessage() in extraScript .

extensions

List<String>

List of strings are from Echarts extensions, such as themes, components, WebGL, and languages. You can download them from the official ECharts extension list. Insert extensions as raw strings:

const liquidPlugin = r'''

  // copy from liquid.min.js

''';

theme

String

You can download built-in ECharts themes or build your own custom themes with the ECharts theme builder. Copy the theme script into the extensions param and register the theme name with this param.

captureAllGestures

bool

( default: false )

Setting captureAllGestures to true is useful when handling 3D rotation and data zoom bars. Note that setting prevents containers like ListViews from reacting to gestures on the charts.

If true, captureHorizontalGestures and captureVerticalGestures are forced true.

captureHorizontalGestures

bool

( default: false )

Only capture horizontal gestures.

captureVerticalGestures

bool

( default: false )

Only capture vertical gestures.

onLoad

void Function(WebViewController)?

The callback when first time the chart is loaded and rendered. You can get the webview controller from this function to do your magic.

reloadAfterInit

bool

( default: false )

If you have trouble in rendering charts in "Movable Widgets"(ListView, SliverView, PageVIew...) on iOS, try setting reloadAfterInit to true .

onWebResourceError

void Function(WebViewController, Exception)?

Handle the web resource error.

Blog

Reactive Echarts Flutter Widget

A performance optimization of Flutter WebView


If you have any suggestions or requests, please open an issue.

The gallery GIF is from chenjiandongx

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目