搜尋套件、儲存庫與 APP 分類

chart_sparkline 封面
套件詳情v1.1.2

chart_sparkline

適用於 Flutter 的美觀折線圖。包含平均線、最高值和最低值。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
7490
喜歡數
135
Pub 分數
150

安裝套件

flutter pub add chart_sparkline

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

Chart Sparkline 是一個 Flutter 套件,可實現緊湊且視覺上吸引人的微型圖表。它在小空間內顯示趨勢,具備平均線功能,並突出顯示最大值和最小值。非常適合儀表板和資料摘要,支援 Android、iOS、Web、macOS、Windows 和 Linux 等多個平台。該套件輕量級,可無縫整合至現有的 Flutter 應用程式中。其簡潔設計提升資料可讀性,又不會讓使用者感到資訊過載。

適用情境

  • 儀表板小部件
  • 即時資料追蹤
  • 效能趨勢可視化
  • 緊湊的資料摘要
  • 財務指標顯示

主要特色

  • 平均線可視化
  • 突出顯示最大值和最小值
  • 極簡設計
  • 跨平台支援
  • 與 Flutter 的輕鬆整合
  • 平滑渲染

適合對象

  • 數據儀表板
  • 行動與Web應用程式
  • 分析介面
  • 財務與健康追蹤應用
  • 需要緊湊圖表的 UI

使用建議

  • 最適合小型數據集
  • 有限的互動性
  • 無工具提示或標籤
  • 需要手動格式化資料
  • 不適合複雜的圖表類型

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

pub package

chart_sparkline

Beautiful sparkline charts for Flutter.

screenshot

Online Demo

Online Demo

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:chart_sparkline/chart_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(
    MaterialApp(
      home: Scaffold(
        body: Center(
          child: Container(
            width: 300.0,
            height: 100.0,
            child: Sparkline(
              data: data,
            ),
          ),
        ),
      ),
    ),
  );
}

base example screenshot

Customization

Sparkline
Property Default
lineWidth 2.0
lineColor Colors.lightBlue
lineGradient null

Example:

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

lineopts example screenshot

Sparkline(
  data: data,
  lineWidth: 10.0,
  lineGradient: 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]
pointIndex null
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.
atIndex Draw one point at the index specified by pointIndex.

Example:

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

all points example screenshot

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

last point example screenshot

Sparkline(
  data: data,
  pointsMode: PointsMode.atIndex,
  pointIndex: 7,
  pointSize: 8.0,
  pointColor: Colors.amber,
);

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:

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

fill below example screenshot

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

fill above example screenshot

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

fill above example screenshot

Smoothing
Sparkline(
  data: data,
  useCubicSmoothing: true,
  cubicSmoothingFactor: 0.2,
),

cubic smoothing example screenshot

Average Line
Sparkline(
  data: data,
  averageLine: true,
  averageLabel: true,
),

cubic smoothing example screenshot

first, last, highest and the lowest
Sparkline(
  data: data,
  kLine: ['max', 'min', 'first', 'last'],
),

cubic smoothing example screenshot

Grid Line
Sparkline(
  gridLinelabelPrefix: '\$',
  gridLineLabelPrecision: 3,
  enableGridLines: true,
),

cubic smoothing example screenshot

Animation Line

Online Demo

AnimatedBuilder(
  animation: AnimationController(duration: const Duration(seconds: 1), vsync: this),
  builder: (context, child) => Sparkline(
    data: [0.0, 1.0, 1.5, 2.0, 0.0, 0.0, -0.5, -1.0, -0.5, 0.0, 0.0],
    animationController: _controller,
    pointsMode: PointsMode.all,
    pointSize: 8.0,
  ),
),

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
  • [x] animate drawing a single sparkline
  • [ ] gesture detector to select closest point to tap
  • [x] baseline
  • [x] different fill modes [above/below/none]
  • [x] fix edge points overflowing by offsetting by lineWidth
  • [x] better corner rounding
  • [x] axis labels
  • [x] gradient shader on line paint
  • [x] gradient shader on fill paint
  • [ ] multiple overlapping sparklines on a shared axis

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。