• Stars
    star
    139
  • Rank 257,649 (Top 6 %)
  • Language
    Dart
  • License
    MIT License
  • Created over 3 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Customizable charts library for flutter.

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

More Repositories

1

android_dbinspector

Android library for viewing, editing and sharing in app databases.
Kotlin
945
star
2

rails-handbook

Describing the development process used by the Infinum Rails Team.
Slim
763
star
3

FBAnnotationClustering

iOS library for clustering map notifications in an easy and performant way
Objective-C
713
star
4

Android-Goldfinger

Android library to simplify Biometric authentication implementation.
Java
652
star
5

ios-viper-xcode-templates

Used for generating template files for the VIPER architecture, which solves the common Massive View Controller issues in iOS apps.
HTML
576
star
6

phrasing

Edit phrases inline for your Ruby on Rails applications!
Ruby
544
star
7

eightshift-boilerplate

This repository contains all the tools you need to start building a modern WordPress theme, using all the latest front end development tools.
PHP
511
star
8

Android-GoldenEye

A wrapper for Camera1 and Camera2 API which exposes simple to use interface.
Kotlin
375
star
9

cookies_eu

Gem to add cookie consent to Rails application
Haml
266
star
10

dox

Automated API documentation from Rspec
Ruby
234
star
11

MjolnirRecyclerView

[DEPRECATED] This library is no longer maintained and it will not receive any more updates.
Java
220
star
12

ios-nuts-and-bolts

iOS bits and pieces that you can include in your project to make your life a bit easier.
Swift
195
star
13

Japx

Lightweight parser for the complex JSON:API (http://jsonapi.org/) structure.
Swift
150
star
14

datx

DatX is an opinionated JS/TS data store. It features support for simple property definition, references to other models and first-class TypeScript support.
TypeScript
137
star
15

learnQuery

Learn JavaScript fundamentals by building your own jQuery equivalent library
JavaScript
137
star
16

flutter-dasher

Dart
116
star
17

floggy

Customizable logger for dart and flutter applications.
Dart
115
star
18

android-complexify

An Android library which makes checking the quality of user's password a breeze.
Java
113
star
19

Android-Prince-of-Versions

Android library for handling application updates.
Java
104
star
20

android_connectionbuddy

Utility library for handling connectivity change events.
Java
94
star
21

eightshift-docs

A documentation website for Eightshift open source projects
JavaScript
79
star
22

eightshift-frontend-libs

Frontend library that exposes custom scripts and styles for modern WordPress projects
JavaScript
69
star
23

Retromock

Java library for mocking responses in a Retrofit service.
Kotlin
67
star
24

eightshift-libs

Library that is meant to be used inside Eightshift Boilerplate and Eightshift Boilerplate Plugin libs via composer in order to be able to easily set up a modern development process.
PHP
61
star
25

frontend-handbook

Our handbook based on 10 years of experience in Frontend/JS development
Slim
57
star
26

Locker

Securely lock your secrets under the watch of TouchID or FaceID keeper 🔒
Swift
50
star
27

emotion-normalize

normalize.css but for emotion.js
JavaScript
50
star
28

mobx-jsonapi-store

JSON API Store for MobX
TypeScript
48
star
29

Dagger-2-Example

Dagger 2 example project
Java
44
star
30

ios-prince-of-versions

Library used for easier versioning of your applications, allowing you to prompt your users to update the app to the newest version
Swift
43
star
31

enumerations

Better Rails Enumerations
Ruby
37
star
32

kotlin-jsonapix

JsonApiX is an Android, annotation processor library that was made to transform regular Kotlin classes into their JSON API representations, with the ability to serialize or deserialize them to or from strings.
Kotlin
36
star
33

eightshift-boilerplate-plugin

This repository contains all the tools you need to start building a modern WordPress plugin.
PHP
36
star
34

mobx-collection-store

Data collection store for MobX
TypeScript
35
star
35

android-sentinel

Sentinel is a simple one screen UI which provides a standardised entry point for tools used in development and QA alongside device, application and permissions data.
Kotlin
35
star
36

decoupled-json-content

JavaScript
30
star
37

wordpress-handbook

Official WordPress handbook at Infinum
Slim
30
star
38

webpack-asset-pipeline

🚀 A missing link for the asset pipeline alternative with Webpack.
JavaScript
30
star
39

ios-loggie

Simplify debugging by showing network requests of your app as they happen.
Swift
30
star
40

flutter-plugins-locker

Flutter plugin that secures your secrets in keychain using biometric authentication (Fingerprint, Touch ID, Face ID...).
Dart
29
star
41

default_rails_template

Default template for generating new Rails applications.
Ruby
27
star
42

eightshift-forms

WordPress plugin project for Gutenberg forms
PHP
27
star
43

media-blender

Easy and predictable SASS/SCSS media queries
CSS
26
star
44

android-collar

Gradle plugin which collects all analytics screen names, events and user properties for Android projects.
Kotlin
26
star
45

secrets_cli

CLI for storing and reading your secrets via vault
Ruby
25
star
46

flutter-plugins-japx

JSON API parser for Flutter
Dart
24
star
47

flutter-bits

Flutter
Dart
22
star
48

react-mobx-translatable

Make React components translatable using MobX
JavaScript
21
star
49

dungeons-and-dragons

🎲 Dungeons & Dragons Character builder and keeper (work in progress)
TypeScript
19
star
50

android-crash-handler

Utility library which handles crash handler configuration
Java
19
star
51

qa-handbook

Describing the processes used by the Infinum QA Team
Slim
18
star
52

iOS-Bugsnatch

Swift
18
star
53

eightshift-coding-standards

Eightshift coding standards for WordPress
PHP
16
star
54

jsonapi-query_builder

Ruby
14
star
55

thrifty-retrofit-converter

Retrofit converter which uses Thrifty for Apache Thrift-compatible serialization
Java
13
star
56

json-wp-post-parser

JSON Post Parser plugin parses your content and saves it as JSON available in REST posts and pages endpoints.
PHP
13
star
57

swift-style-guide

12
star
58

generator-infinitely-static

💫 Static page generator with routes support thats infinitely awesome
JavaScript
11
star
59

react-responsive-ssr

TypeScript
11
star
60

JS-React-Example

Infinum's way of doing React
TypeScript
10
star
61

ngx-hal

Angular datastore library with HAL support
TypeScript
10
star
62

fiscalizer

A gem for fiscalizing invoices in Croatia using Ruby.
Ruby
9
star
63

ember-form-object

Form object pattern in ember apps
JavaScript
9
star
64

js-talks

✨ Interesting talks and mini lectures about new and cool stuff that's going on in the world of JS development, organized by the Infinum JS team
9
star
65

android-handbook

Slim
8
star
66

js-linters

Infinum's JS team linter rules
TypeScript
7
star
67

auth-worker

OAuth2 Service Worker handler
TypeScript
7
star
68

array_validator

Array Validations for ActiveModel
Ruby
7
star
69

eightshift-storybook

Storybook package for Eightshift-Boilerplate
7
star
70

icomcom-react

💬 A React component for handling communication with content in <iframe />
JavaScript
7
star
71

dox-demo

Demo app for dox gem:
HTML
6
star
72

android-localian

Android library that manages your application locale and language across multiple Android API levels.
Kotlin
6
star
73

ios-handbook

Slim
6
star
74

flutter-prince-of-versions

Library used for easier versioning of your applications, allowing you to prompt your users to update the app to the newest version
Dart
6
star
75

learn-react

👋 ⚛️ Learn React by implementing your own!
TypeScript
5
star
76

I18n-js

Javascript library for string internationalization.
CoffeeScript
5
star
77

ios-collar

In-app analytics debugging tool
Swift
5
star
78

ngx-form-object

Reactive forms manager
TypeScript
5
star
79

ios-sentinel

Developer’s toolbox for debugging applications
Swift
4
star
80

mobx-keys-store

Keys store for MobX
TypeScript
4
star
81

mysterious-sampler

Swift
4
star
82

rails-infinum-jsonapi_example_app_old

Ruby
4
star
83

phrasing_plus

Phrasing extension for editing images inline
Ruby
4
star
84

eightshift-web-components

Web components library that exposes custom scripts and styles for modern WordPress projects
Svelte
4
star
85

Install-Flutter-Version-Manager-Bitrise

Shell
4
star
86

infinum_setup

Setup script
Ruby
4
star
87

loglevel-filesave

Loglevel plugin for saving logs to the file
JavaScript
4
star
88

eightshift-blocks

Project dedicated to use inside WP Boilerplate and WP Boilerplate Plugin projects via composer to be able to easily setup modern development process for Gutenberg blocks..
PHP
3
star
89

data_sync

Rails plugin for database and file synchronization
Ruby
3
star
90

next-passenger

next.js with passenger proof of concept
Dockerfile
3
star
91

SocketMan

Android WebSocket client app
Java
3
star
92

react-asset-collector

Collect assets from react components so you can do HTTP2 push
JavaScript
3
star
93

rails_log_book

Ruby
3
star
94

mina-secrets

Mina plugin for secrets_cli gem
Ruby
2
star
95

docusaurus-theme

Infinum Docusaurus teme
JavaScript
2
star
96

ngx-nuts-and-bolts

A collection of commonly used pieces of Angular-related code that we use everyday at Infinum.
TypeScript
2
star
97

money_with_date

Extension for the money gem which adds dates to Money objects.
Ruby
2
star
98

blog-android-permissions

Java
2
star
99

JS-RxWorkshop

TypeScript
2
star
100

analytics-handbook

2
star