패키지, 저장소 및 앱 카테고리 검색

charts_painter 표지
패키지 상세v3.1.1

charts_painter

커스텀 페인터로 제작된 Flutter용 고도로 사용자 정의 가능하고 확장 가능한 차트 라이브러리

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
5.5천
좋아요
313
Pub 점수
130

패키지 설치

flutter pub add charts_painter

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

charts_painter는 커스터마이징 및 확장성이 뛰어난 Flutter용 차트 라이브러리로, 사용자 정의 페인터를 기반으로 구축되었습니다. 개발자가 특정 요구 사항에 맞춰 정밀하고 성능이 우수한 시각화를 만들 수 있도록 도와줍니다. 렌더링에 대한 저수준 제어를 제공하여 복잡하거나 독특한 차트 디자인에 적합합니다. Android, iOS, Web, macOS, Windows, Linux 등 주요 플랫폼 전반에서 지원되며, 어디서나 일관된 차트 렌더링을 보장합니다. 확장성 덕분에 개발자는 커스텀 차트 유형과 스타일을 쉽게 구현할 수 있습니다.

사용 사례

  • 사용자 지정 데이터 시각화 대시보드
  • 앱에서의 고성능 차트 렌더링
  • 표준 라이브러리 이상의 맞춤형 차트 디자인
  • 세밀한 제어가 필요한 데이터 집약형 애플리케이션
  • 사용자 정의 애니메이션을 갖춘 인터랙티브 차트 컴포넌트

주요 기능

  • 최적의 성능을 위해 사용자 정의 페인터로 구축됨
  • 사용자 정의 차트 유형을 위한 확장 가능한 아키텍처
  • 다중 플랫폼 지원
  • 높은 사용자 정의 가능한 외관 및 동작
  • 그림 로직에 대한 세밀한 제어

적합한 대상

  • 차트 렌더링에 대한 완전한 제어가 필요한 개발자
  • 특수 시각화 도구를 개발하는 팀
  • 경량이고 빠른 차트가 필요한 앱
  • 표준 차트 패키지가 너무 제한적인 프로젝트
  • 디자이너와 개발자가 고유한 UI에서 협업한다

고려 사항

  • Flutter에서 커스텀 페인팅에 대한 지식이 필요합니다
  • 고급 차트 패키지와 비교해 학습 곡선이 더 가파름
  • 터치 상호작용 및 애니메이션의 수동 처리
  • 제한된 박스형 차트 유형
  • UI/그래픽 경험을 가진 고급 사용자에게 가장 적합

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

Charts painter pub package

Idea behind this lib is to allow highly customizable charts. By having items and decorations as Widgets or predefined renderers where you can achieve the look of desired chart.

3.0 Migration guide

Read the migration guide if you are interested in migrating from 2.0 to 3.0.

Web demo

Check out web demo to see what’s possible to do with the charts_painter

Usage

Add it to your package’s pubspec.yaml file

charts_painter: latest

Start with the Chart

The Widget you can use is Chart or AnimatedChart if you want to show animations when changing chart state. It has parameters of height, width and ChartState.

Chart State

ChartState describes how the chart should look. The chart drawing is divided into sections, so the ChartState has these parameters:

  • Data: What is the data that needs to be shown
  • Item options: How to draw that data points into items on chart
  • Decorations: Various additional objects that enhance and completes look of the chart. They are divided into backgroundDecorations (behind items) or in foregroundDecorations (in front of items).
  • Chart behaviour: Not used for drawing, but contain scrollable and item click logic

Now we will explain each of these:

Data

The ChartData only required parameter is List<List<ChartItem>>. So, most basic data would look like:

ChartData([
    [
      ChartItem(2),
      ChartItem(5),
      ChartItem(7),
      ChartItem(11),
      ChartItem(4),
    ]
  ])

The reason for double list (List<List<) is that you can display multiple data lines alongside each other.

ChartData([
    [2, 6, 8, 4, 6, 8].map((e) => ChartItem<void>(e.toDouble())).toList(),
    [3, 5, 2, 7, 0, 4].map((e) => ChartItem<void>(e.toDouble())).toList(),
  ],);

Chart Item requires max height parameter, but also has optional min and T value which can be any kind of value that you can attach to your items, if you have need for it.

When displaying multiple data lines, you might be interested in dataStrategy parameter. It controls how these multiple lines are drawn. For example, if you want to stack bars, one on top of another, you can use StackDataStrategy.

Parameter valueAxisMaxOver will add that value to currently the highest value that functions like a some sort of top padding.

Item options

For item options, you can use one of three defined options:

  • BarItemOptions - for drawing bar or candle items
  • BubbleItemOptions - for draw bubble items
  • WidgetItemOptions - for drawing any kind of widget.

You could create anything with WidgetItemOptions, but Bar and Bubble are often used and here they are drawn directly on canvas to make sure chart is performant. This graphic might help when choosing:

Options have several parameter, and the required is itemBuilder. With it, you describe how to build an item. For example, to make bar item:

barItemBuilder: (data) {
    return BarItem(
      radius: const BorderRadius.vertical(
        top: Radius.circular(24.0),
      ),
      color: Colors.red.withOpacity(0.4),
    );
  },

The data that’s passed into the builder can be used to build different kind of item based on the item value (data.item.value), his index in data (data.itemIndex) or based on which data list it belongs to (data.listIndex).

Besides builder, the other useful parameters in item options are maxBarWidth , minBarWidth , startPosition , padding.

If you want to listen to item taps you can do it by setting ChartBehaviour(onItemClicked) - you can read more about ChartBehaviour below. In case of a WidgetItemOptions, you could also provide GestureDetectors and Buttons and they will all work.

Decorations

Decorations enhance and complete the look of the chart. Everything that’s drawn on a chart, and it’s not a chart item is considered a decoration. So that means a lot of the chart will be a decoration. Just like with the items, you can use WidgetDecoration to draw any kind of the decoration, but the most common cases for decoration are already made on a canvas and ready to be used:

horizontal_decoration Horizontal decoration vertical_decoration Vertical decoration grid_decoration Grid decoration
sparkline_decoration Sparkline decoration
Widget decoration

There are only two parameters in WidgetDecoration:

WidgetDecoration(
    widgetDecorationBuilder: (context, chartState, itemWidth, verticalMultiplayer) {
      return Container(); // Your widget goes here
    },
    margin: const EdgeInsets.only(left: 20),
)

The builder returns context, chartState where from you can read details like all the values. And itemWidth and verticalMultiplier can help with laying out and position the decoration:

If you do add margins to the chart, your decoration widget will be positioned from start of the chart (not affected by the margins), so you can draw in the margins. You can add padding that equals the chart margins which will set you to the start of the first item so calculations including itemWidth or verticalMultiplier works correctly:

    widgetDecorationBuilder: (context, chartState, itemWidth, verticalMultiplayer) {
      return Padding(padding: chartState.defaultMargin, child: YourWidget());
    },

Chart behaviour

Chart behaviour has just two parameters:

  • scrollSettings - used to config the chart to be scrollable or not. You still need to wrap it with SingleChildScrollView.
  • onItemClicked - when set the tap events on items are registered and will invoke this method. If you're using WidgetItemOptions, you could set a gesture detector there, but this works with both BarItemOptions, BubbleItemOptions and WidgetItemOptions.

Complete example

So, to wrap all of this up. The most minimal example of a bar chart with data, barItemOptions* and no decorations would looks like:

Chart(
    state: ChartState<void>(
      data: ChartData(
          [[3,5,7,9,4,3,6].map((e) => ChartItem<void>(e.toDouble())).toList()]
      ),
      itemOptions: BarItemOptions()
    ),
  );

Which will produce a chart looking like:

A bit more complex example with two data lists coloured differently and grid decoration would look like:

Chart(
    state: ChartState<void>(
        data: ChartData(
          [
            [3, 5, 7, 9, 4, 3, 6].map((e) => ChartItem<void>(e.toDouble())).toList(),
            [5, 2, 8, 4, 5, 5, 2].map((e) => ChartItem<void>(e.toDouble())).toList(),
          ],
        ),
        itemOptions: BarItemOptions(barItemBuilder: (itemBuilderData) {
          // Setting the different color based if the item is from first or second list
          return BarItem(color: itemBuilderData.listIndex == 0 ? Colors.red : Colors.blue);
        }),
        backgroundDecorations: [
          HorizontalDecoration(axisStep: 2, showValues: true),
        ])
  );

Which produces a chart:

There’s a lot more things possible with this package, but to keep this README readable, we recommend you checking out the demo and showcase web app.

Scrollable chart

Charts can also be scrollable, to use scroll first you have to wrap chart your chart in SingleChildScrollView widget. Then in ChartBehaviour make sure you set isScrollable to true.

https://raw.githubusercontent.com/infinum/flutter-charts/master/assets/scrollable_chart.gif

scrollable_chart

To make sure you can make any chart you want, we have included DecorationsRenderer as widget that you can use outside of the chart bounds. That is useful for fixed legends:

More examples

Line charts

Line chart with multiple values

example code

https://raw.githubusercontent.com/infinum/flutter-charts/master/assets/line_chart_animating.gif

Bar charts

Bar chart with area

example code

https://raw.githubusercontent.com/infinum/flutter-charts/master/assets/bar_chart_animating.gif

카테고리

의존성

의존성 목록 2 개

소스 저장소

이 패키지를 사용하는 프로젝트