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

插件详情v0.1.0

flutter_sparkline

适用于 Flutter 的精美折线图。

近 30 天下载
426
喜欢数
72
Pub 分数
30

安装插件

flutter pub add flutter_sparkline

插件介绍

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

Flutter Sparkline 是一个轻量级包,用于在 Flutter 应用中渲染紧凑且视觉上吸引人的微型图表。它使开发者能够直接在文本或 UI 元素中显示小型、简单的折线图,非常适合在有限空间内展示随时间变化的趋势。该包支持自定义颜色、线条宽度和数据点样式,适用于仪表板、报告和分析界面。凭借简洁的 API 和高效性能,它可无缝集成到现有的 Flutter 项目中。

适合场景

  • 在仪表板中显示趋势数据
  • 在表格中可视化指标
  • 增强应用分析用户界面
  • 以紧凑形式显示历史数据
  • 在列表项中集成微型图表

主要特点

  • 极简主义,高影响力可视化
  • 可自定义的线条颜色和宽度
  • 平滑曲线渲染
  • 支持动态数据更新
  • 轻量且快速的性能

适合对象

  • 受限空间中的数据可视化
  • 移动应用分析
  • 实时指标显示
  • 需要微妙趋势指示器的UI
  • 寻求简单图表功能而无需复杂性的开发者

使用建议

  • 仅限基于行的 sparklines
  • 无交互功能,例如工具提示
  • 不适合大型数据集
  • 需要手动处理数据缩放
  • 最好与小型、离散的数据系列一起使用

原始 README

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

pub package

flutter_sparkline

Beautiful sparkline charts for Flutter.

screenshot

Installation

Install the latest version from pub.

Quick Start

Import the package, create a Sparkline, and pass it your data.

import 'package:flutter/material.dart';
import 'package:flutter_sparkline/flutter_sparkline.dart';

void main() {
  var data = [0.0, 1.0, 1.5, 2.0, 0.0, 0.0, -0.5, -1.0, -0.5, 0.0, 0.0];
  runApp(
    new MaterialApp(
      home: new Scaffold(
        body: new Center(
          child: new Container(
            width: 300.0,
            height: 100.0,
            child: new Sparkline(
              data: data,
            ),
          ),
        ),
      ),
    ),
  );
}

base example screenshot

Customization

Sparkline
Property Default
lineWidth 2.0
lineColor Colors.lightBlue
lineGradient null

Example:

new Sparkline(
  data: data,
  lineWidth: 5.0,
  lineColor: Colors.purple,
);

lineopts example screenshot

new Sparkline(
  data: data,
  lineWidth: 10.0,
  lineGradient: new LinearGradient(
    begin: Alignment.topCenter,
    end: Alignment.bottomCenter,
    colors: [Colors.purple[800], Colors.purple[200]],
  ),
);

lineopts example screenshot


Points
Property Default
pointsMode PointsMode.none
pointSize 4.0
pointColor Colors.lightBlue[800]
PointsMode Description
none (default) Do not draw individual points.
all Draw all the points in the data set.
last Draw only the last point in the data set.

Example:

new Sparkline(
  data: data,
  pointsMode: PointsMode.all,
  pointSize: 8.0,
  pointColor: Colors.amber,
);

all points example screenshot

new Sparkline(
  data: data,
  pointsMode: PointsMode.last,
  pointSize: 8.0,
  pointColor: Colors.amber,
);

last point example screenshot


Fill
Property Default
fillMode FillMode.none
fillColor Colors.lightBlue[200]
fillGradient null
FillMode Description
none (default) Do not fill, draw only the sparkline.
above Fill the area above the sparkline.
below Fill the area below the sparkline.

Example:

new Sparkline(
  data: data,
  fillMode: FillMode.below,
  fillColor: Colors.red[200],
);

fill below example screenshot

new Sparkline(
  data: data,
  fillMode: FillMode.above,
  fillColor: Colors.red[200],
);

fill above example screenshot

new Sparkline(
  data: data,
  fillMode: FillMode.below,
  fillGradient: new LinearGradient(
    begin: Alignment.topCenter,
    end: Alignment.bottomCenter,
    colors: [Colors.red[800], Colors.red[200]],
  ),
);

fill above example screenshot


Todo:
  • [x] simple sparkline
  • [x] custom line width
  • [x] custom line color
  • [x] optional rounded corners
  • [x] fill
  • [x] embiggen individual points/change color
  • [x] different points modes [all/last/none]
  • [ ] animate between two sparklines
  • [ ] animate drawing a single sparkline
  • [ ] gesture detector to select closest point to tap
  • [ ] baseline
  • [x] different fill modes [above/below/none]
  • [x] fix edge points overflowing by offsetting by lineWidth
  • [ ] better corner rounding
  • [ ] axis labels
  • [x] gradient shader on line paint
  • [x] gradient shader on fill paint
  • [ ] multiple overlapping sparklines on a shared axis
  • [ ] tests

所属分类

源码仓库

使用此插件的项目

暂无相关数据。